load-student.spec.js 415 Bytes
Newer Older
Wolfram Kriesing's avatar
Wolfram Kriesing committed
1 2 3 4 5 6 7 8 9
import { fetch } from './backend';

const cache = {};
export const loadStudent = ({ studentId }) => {
  if (!cache[studentId]) {
    cache[studentId] = fetch({ studentId });
  }
  return cache[studentId];
};
10 11 12 13 14 15 16 17

describe('Load a student', () => {
  it('from the cache', () => {
    cache[42] = 'student 42';
    const student = loadStudent({ studentId: 42 });
    assertThat(student, equalTo('student 42'));
  });
});