Commit 2c485ba3 authored by Wolfram Kriesing's avatar Wolfram Kriesing

Inject the `cache` variable.

parent 6ef5b2d5
const { assertThat, equalTo } = require('hamjest');
const { fetch } = require('./backend');
const cache = {};
const loadStudent = ({ studentId }) => {
const loadStudent = ({ studentId, cache }) => {
if (!cache[studentId]) {
cache[studentId] = fetch({ studentId });
}
......@@ -11,8 +10,8 @@ const loadStudent = ({ studentId }) => {
describe('Load a student', () => {
it('from the cache', () => {
cache[42] = 'student 42';
const student = loadStudent({ studentId: 42 });
const cache = { 42: 'student 42' }; // <<< no more globals :)
const student = loadStudent({ studentId: 42, cache });
assertThat(student, equalTo('student 42'));
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment