Skip to content

Commit

Permalink
tes(js): add test for reactive wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Mar 5, 2021
1 parent 8356031 commit f83d3ec
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createReactiveWrapper } from '../createReactiveWrapper';

describe('createReactiveWrapper', () => {
test('runs the reactive values', () => {
const { reactive, runReactives } = createReactiveWrapper();
let lastValue = -1;
const computeValue = jest.fn(() => {
lastValue++;
return lastValue;
});
const computeValue2 = jest.fn(() => 0);

const callResult = reactive(computeValue);
expect(computeValue).toHaveBeenCalledTimes(1);
expect(callResult.value).toEqual(0);

const callResult2 = reactive(computeValue2);
expect(computeValue2).toHaveBeenCalledTimes(1);
expect(callResult2.value).toEqual(0);

runReactives();

expect(computeValue).toHaveBeenCalledTimes(2);
expect(callResult.value).toEqual(1);

expect(computeValue2).toHaveBeenCalledTimes(2);
expect(callResult2.value).toEqual(0);
});
});

0 comments on commit f83d3ec

Please sign in to comment.