Skip to content

Commit d2d3ac5

Browse files
committed
up
1 parent 458817d commit d2d3ac5

File tree

2 files changed

+67
-67
lines changed

2 files changed

+67
-67
lines changed

tests/derived.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ describe("derived", () => {
3333
const spyEffect = jest.fn(() => d());
3434
effect(spyEffect);
3535

36-
expectSpy(spyEffect, 1, []);
37-
expectSpy(spyDerived, 1, [], 2);
36+
expectSpy(spyEffect, 1, { args: [] });
37+
expectSpy(spyDerived, 1, { args: [], result: 2 });
3838
await waitScheduler();
39-
expectSpy(spyEffect, 2, []);
40-
expectSpy(spyDerived, 2, [], 6);
39+
expectSpy(spyEffect, 2, { args: [] });
40+
expectSpy(spyDerived, 2, { args: [], result: 6 });
4141
state.b = 4;
4242
await waitScheduler();
43-
expectSpy(spyEffect, 3, []);
44-
expectSpy(spyDerived, 3, [], 12);
43+
expectSpy(spyEffect, 3, { args: [] });
44+
expectSpy(spyDerived, 3, { args: [], result: 12 });
4545
});
4646

4747
test("derived does not update when unrelated property changes, but updates when dependencies change", async () => {
@@ -51,25 +51,25 @@ describe("derived", () => {
5151
const spyEffect = jest.fn(() => d());
5252
effect(spyEffect);
5353

54-
expectSpy(spyEffect, 1, []);
55-
expectSpy(spyDerived, 1, [], 3);
54+
expectSpy(spyEffect, 1, { args: [] });
55+
expectSpy(spyDerived, 1, { args: [], result: 3 });
5656

5757
state.c = 10;
5858
await waitScheduler();
59-
expectSpy(spyEffect, 1, []);
60-
expectSpy(spyDerived, 1, [], 3);
59+
expectSpy(spyEffect, 1, { args: [] });
60+
expectSpy(spyDerived, 1, { args: [], result: 3 });
6161
});
6262

6363
test("derived does not notify when value is unchanged", async () => {
6464
const state = reactive({ a: 1, b: 2 });
6565
const d = derived(() => state.a + state.b);
6666
const spy = jest.fn();
6767
effect(() => spy(d()));
68-
expectSpy(spy, 1, [3]);
68+
expectSpy(spy, 1, { args: [3] });
6969
state.a = 1;
7070
state.b = 2;
7171
await waitScheduler();
72-
expectSpy(spy, 1, [3]);
72+
expectSpy(spy, 1, { args: [3] });
7373
});
7474

7575
test("multiple deriveds can depend on same state", async () => {
@@ -80,48 +80,48 @@ describe("derived", () => {
8080
const spy2 = jest.fn();
8181
effect(() => spy1(d1()));
8282
effect(() => spy2(d2()));
83-
expectSpy(spy1, 1, [3]);
84-
expectSpy(spy2, 1, [2]);
83+
expectSpy(spy1, 1, { args: [3] });
84+
expectSpy(spy2, 1, { args: [2] });
8585
state.a = 3;
8686
await waitScheduler();
87-
expectSpy(spy1, 2, [5]);
88-
expectSpy(spy2, 2, [6]);
87+
expectSpy(spy1, 2, { args: [5] });
88+
expectSpy(spy2, 2, { args: [6] });
8989
});
9090

9191
test("derived can return objects", async () => {
9292
const state = reactive({ a: 1, b: 2 });
9393
const d = derived(() => state.a + state.b);
9494
const spy = jest.fn();
9595
effect(() => spy(d()));
96-
expectSpy(spy, 1, [3]);
96+
expectSpy(spy, 1, { args: [3] });
9797
state.a = 5;
9898
await waitScheduler();
99-
expectSpy(spy, 2, [7]);
99+
expectSpy(spy, 2, { args: [7] });
100100
});
101101

102102
test("derived can depend on arrays", async () => {
103103
const state = reactive({ arr: [1, 2, 3] });
104104
const d = derived(() => state.arr.reduce((a, b) => a + b, 0));
105105
const spy = jest.fn();
106106
effect(() => spy(d()));
107-
expectSpy(spy, 1, [6]);
107+
expectSpy(spy, 1, { args: [6] });
108108
state.arr.push(4);
109109
await waitScheduler();
110-
expectSpy(spy, 2, [10]);
110+
expectSpy(spy, 2, { args: [10] });
111111
state.arr[0] = 10;
112112
await waitScheduler();
113-
expectSpy(spy, 3, [19]);
113+
expectSpy(spy, 3, { args: [19] });
114114
});
115115

116116
test("derived can depend on nested reactives", async () => {
117117
const state = reactive({ nested: { a: 1 } });
118118
const d = derived(() => state.nested.a * 2);
119119
const spy = jest.fn();
120120
effect(() => spy(d()));
121-
expectSpy(spy, 1, [2]);
121+
expectSpy(spy, 1, { args: [2] });
122122
state.nested.a = 5;
123123
await waitScheduler();
124-
expectSpy(spy, 2, [10]);
124+
expectSpy(spy, 2, { args: [10] });
125125
});
126126

127127
test("derived can be called multiple times and returns same value if unchanged", async () => {
@@ -155,14 +155,14 @@ describe("derived", () => {
155155
const unsubscribe = effect(() => {
156156
d();
157157
});
158-
expectSpy(spy, 1, [1]);
158+
expectSpy(spy, 1, { args: [1] });
159159
state.a = 2;
160160
await waitScheduler();
161-
expectSpy(spy, 2, [2]);
161+
expectSpy(spy, 2, { args: [2] });
162162
unsubscribe();
163163
state.a = 3;
164164
await waitScheduler();
165-
expectSpy(spy, 2, [2]);
165+
expectSpy(spy, 2, { args: [2] });
166166
});
167167

168168
test("derived should not be recomputed when called from effect if none of its source changed", async () => {
@@ -209,9 +209,9 @@ describe("nested derived", () => {
209209
const d2 = derived(() => d1() * 2);
210210
const spy = jest.fn();
211211
effect(() => spy(d2()));
212-
expectSpy(spy, 1, [6]);
212+
expectSpy(spy, 1, { args: [6] });
213213
state.a = 3;
214214
await waitScheduler();
215-
expectSpy(spy, 2, [10]);
215+
expectSpy(spy, 2, { args: [10] });
216216
});
217217
});

tests/effect.test.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ describe("effect", () => {
1919
const state = reactive({ a: 1 });
2020
const spy = jest.fn();
2121
effect(() => spy(state.a));
22-
expectSpy(spy, 1, [1]);
22+
expectSpy(spy, 1, { args: [1] });
2323
state.a = 2;
2424
await waitScheduler();
25-
expectSpy(spy, 2, [2]);
25+
expectSpy(spy, 2, { args: [2] });
2626
});
2727
it("effect should unsubscribe previous dependencies", async () => {
2828
const state = reactive({ a: 1, b: 10, c: 100 });
@@ -34,33 +34,33 @@ describe("effect", () => {
3434
spy(state.c);
3535
}
3636
});
37-
expectSpy(spy, 1, [10]);
37+
expectSpy(spy, 1, { args: [10] });
3838
state.b = 20;
3939
await waitScheduler();
40-
expectSpy(spy, 2, [20]);
40+
expectSpy(spy, 2, { args: [20] });
4141
state.a = 2;
4242
await waitScheduler();
43-
expectSpy(spy, 3, [100]);
43+
expectSpy(spy, 3, { args: [100] });
4444
state.b = 30;
4545
await waitScheduler();
46-
expectSpy(spy, 3, [100]);
46+
expectSpy(spy, 3, { args: [100] });
4747
state.c = 200;
4848
await waitScheduler();
49-
expectSpy(spy, 4, [200]);
49+
expectSpy(spy, 4, { args: [200] });
5050
});
5151
it("effect should not run if dependencies do not change", async () => {
5252
const state = reactive({ a: 1 });
5353
const spy = jest.fn();
5454
effect(() => {
5555
spy(state.a);
5656
});
57-
expectSpy(spy, 1, [1]);
57+
expectSpy(spy, 1, { args: [1] });
5858
state.a = 1;
5959
await waitScheduler();
60-
expectSpy(spy, 1, [1]);
60+
expectSpy(spy, 1, { args: [1] });
6161
state.a = 2;
6262
await waitScheduler();
63-
expectSpy(spy, 2, [2]);
63+
expectSpy(spy, 2, { args: [2] });
6464
});
6565
describe("nested effects", () => {
6666
it("should track correctly", async () => {
@@ -75,20 +75,20 @@ describe("effect", () => {
7575
});
7676
}
7777
});
78-
expectSpy(spy1, 1, [1]);
79-
expectSpy(spy2, 1, [10]);
78+
expectSpy(spy1, 1, { args: [1] });
79+
expectSpy(spy2, 1, { args: [10] });
8080
state.b = 20;
8181
await waitScheduler();
82-
expectSpy(spy1, 1, [1]);
83-
expectSpy(spy2, 2, [20]);
82+
expectSpy(spy1, 1, { args: [1] });
83+
expectSpy(spy2, 2, { args: [20] });
8484
state.a = 2;
8585
await waitScheduler();
86-
expectSpy(spy1, 2, [2]);
87-
expectSpy(spy2, 2, [20]);
86+
expectSpy(spy1, 2, { args: [2] });
87+
expectSpy(spy2, 2, { args: [20] });
8888
state.b = 30;
8989
await waitScheduler();
90-
expectSpy(spy1, 2, [2]);
91-
expectSpy(spy2, 2, [20]);
90+
expectSpy(spy1, 2, { args: [2] });
91+
expectSpy(spy2, 2, { args: [20] });
9292
});
9393
});
9494
describe("unsubscribe", () => {
@@ -98,14 +98,14 @@ describe("effect", () => {
9898
const unsubscribe = effect(() => {
9999
spy(state.a);
100100
});
101-
expectSpy(spy, 1, [1]);
101+
expectSpy(spy, 1, { args: [1] });
102102
state.a = 2;
103103
await waitScheduler();
104-
expectSpy(spy, 2, [2]);
104+
expectSpy(spy, 2, { args: [2] });
105105
unsubscribe();
106106
state.a = 3;
107107
await waitScheduler();
108-
expectSpy(spy, 2, [2]);
108+
expectSpy(spy, 2, { args: [2] });
109109
});
110110
it("effect should call cleanup function", async () => {
111111
const state = reactive({ a: 1 });
@@ -115,15 +115,15 @@ describe("effect", () => {
115115
spy(state.a);
116116
return cleanup;
117117
});
118-
expectSpy(spy, 1, [1]);
118+
expectSpy(spy, 1, { args: [1] });
119119
expect(cleanup).toHaveBeenCalledTimes(0);
120120
state.a = 2;
121121
await waitScheduler();
122-
expectSpy(spy, 2, [2]);
122+
expectSpy(spy, 2, { args: [2] });
123123
expect(cleanup).toHaveBeenCalledTimes(1);
124124
state.a = 3;
125125
await waitScheduler();
126-
expectSpy(spy, 3, [3]);
126+
expectSpy(spy, 3, { args: [3] });
127127
expect(cleanup).toHaveBeenCalledTimes(2);
128128
});
129129
it("should call cleanup when unsubscribing nested effects", async () => {
@@ -148,34 +148,34 @@ describe("effect", () => {
148148
});
149149
return cleanup1;
150150
});
151-
expectSpy(spy1, 1, [1]);
152-
expectSpy(spy2, 1, [10]);
153-
expectSpy(spy3, 1, [100]);
151+
expectSpy(spy1, 1, { args: [1] });
152+
expectSpy(spy2, 1, { args: [10] });
153+
expectSpy(spy3, 1, { args: [100] });
154154
expect(cleanup1).toHaveBeenCalledTimes(0);
155155
expect(cleanup2).toHaveBeenCalledTimes(0);
156156
expect(cleanup3).toHaveBeenCalledTimes(0);
157157
state.b = 20;
158158
await waitScheduler();
159-
expectSpy(spy1, 1, [1]);
160-
expectSpy(spy2, 2, [20]);
161-
expectSpy(spy3, 1, [100]);
159+
expectSpy(spy1, 1, { args: [1] });
160+
expectSpy(spy2, 2, { args: [20] });
161+
expectSpy(spy3, 1, { args: [100] });
162162
expect(cleanup1).toHaveBeenCalledTimes(0);
163163
expect(cleanup2).toHaveBeenCalledTimes(1);
164164
expect(cleanup3).toHaveBeenCalledTimes(0);
165165
(global as any).d = true;
166166
state.a = 2;
167167
await waitScheduler();
168-
expectSpy(spy1, 2, [2]);
169-
expectSpy(spy2, 2, [20]);
170-
expectSpy(spy3, 2, [100]);
168+
expectSpy(spy1, 2, { args: [2] });
169+
expectSpy(spy2, 2, { args: [20] });
170+
expectSpy(spy3, 2, { args: [100] });
171171
expect(cleanup1).toHaveBeenCalledTimes(1);
172172
expect(cleanup2).toHaveBeenCalledTimes(2);
173173
expect(cleanup3).toHaveBeenCalledTimes(1);
174174
state.b = 30;
175175
await waitScheduler();
176-
expectSpy(spy1, 2, [2]);
177-
expectSpy(spy2, 2, [20]);
178-
expectSpy(spy3, 2, [100]);
176+
expectSpy(spy1, 2, { args: [2] });
177+
expectSpy(spy2, 2, { args: [20] });
178+
expectSpy(spy3, 2, { args: [100] });
179179
expect(cleanup1).toHaveBeenCalledTimes(1);
180180
expect(cleanup2).toHaveBeenCalledTimes(2);
181181
expect(cleanup3).toHaveBeenCalledTimes(1);
@@ -187,9 +187,9 @@ describe("effect", () => {
187187
state.b = 40;
188188
state.c = 400;
189189
await waitScheduler();
190-
expectSpy(spy1, 2, [2]);
191-
expectSpy(spy2, 2, [20]);
192-
expectSpy(spy3, 2, [100]);
190+
expectSpy(spy1, 2, { args: [2] });
191+
expectSpy(spy2, 2, { args: [20] });
192+
expectSpy(spy3, 2, { args: [100] });
193193
expect(cleanup1).toHaveBeenCalledTimes(2);
194194
expect(cleanup2).toHaveBeenCalledTimes(2);
195195
expect(cleanup3).toHaveBeenCalledTimes(2);

0 commit comments

Comments
 (0)