Skip to content

Commit 3de5556

Browse files
authored
test(reactive): use vitest fn instead of counting manually (#11746)
1 parent 0387e1b commit 3de5556

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/reactivity/__tests__/ref.spec.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,22 @@ describe('reactivity/ref', () => {
4646
it('ref wrapped in reactive should not track internal _value access', () => {
4747
const a = ref(1)
4848
const b = reactive(a)
49-
let calls = 0
5049
let dummy
51-
52-
effect(() => {
53-
calls++
50+
const fn = vi.fn(() => {
5451
dummy = b.value // this will observe both b.value and a.value access
5552
})
56-
expect(calls).toBe(1)
53+
effect(fn)
54+
expect(fn).toHaveBeenCalledTimes(1)
5755
expect(dummy).toBe(1)
5856

5957
// mutating a.value should only trigger effect once
60-
calls = 0
6158
a.value = 3
62-
expect(calls).toBe(1)
59+
expect(fn).toHaveBeenCalledTimes(2)
6360
expect(dummy).toBe(3)
6461

6562
// mutating b.value should trigger the effect twice. (once for a.value change and once for b.value change)
66-
calls = 0
6763
b.value = 5
68-
expect(calls).toBe(2)
64+
expect(fn).toHaveBeenCalledTimes(4)
6965
expect(dummy).toBe(5)
7066
})
7167

0 commit comments

Comments
 (0)