We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f0d9a98 commit 0066523Copy full SHA for 0066523
tests/derived.test.ts
@@ -27,16 +27,22 @@ describe("derived", () => {
27
28
test("derived updates when dependencies change", async () => {
29
const state = reactive({ a: 1, b: 2 });
30
- const d = derived(() => state.a * state.b);
31
- const spy = jest.fn();
32
- effect(() => spy(d()));
33
- expectSpy(spy, 1, [2]);
+
+ const spyDerived = jest.fn(() => state.a * state.b);
+ const d = derived(spyDerived);
+ const spyEffect = jest.fn(() => d());
34
+ effect(spyEffect);
35
36
+ expectSpy(spyEffect, 1, []);
37
+ expectSpy(spyDerived, 1, [], 2);
38
state.a = 3;
39
await waitScheduler();
- expectSpy(spy, 2, [6]);
40
+ expectSpy(spyEffect, 2, []);
41
+ expectSpy(spyDerived, 2, [], 6);
42
state.b = 4;
43
- expectSpy(spy, 3, [12]);
44
+ expectSpy(spyEffect, 3, []);
45
+ expectSpy(spyDerived, 3, [], 12);
46
});
47
48
test("derived does not update when unrelated property changes", async () => {
tests/helpers.ts
@@ -219,9 +219,16 @@ export async function editInput(input: HTMLInputElement | HTMLTextAreaElement, v
219
return nextTick();
220
}
221
222
-export function expectSpy(spy: jest.Mock, callTime: number, args: any[]): void {
+const noReturnValue = Symbol();
223
+export function expectSpy(
224
+ spy: jest.Mock,
225
+ callTime: number,
226
+ args: any[],
227
+ returnValue: any = noReturnValue
228
+): void {
229
expect(spy).toHaveBeenCalledTimes(callTime);
230
expect(spy).lastCalledWith(...args);
231
+ !noReturnValue && expect(spy).toHaveReturnedWith(returnValue);
232
233
234
afterEach(() => {
0 commit comments