]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactive): use vitest fn instead of counting manually (#11746)
authorMaisha Tremblay <65948611+coderwei99@users.noreply.github.com>
Mon, 2 Sep 2024 09:08:19 +0000 (17:08 +0800)
committerGitHub <noreply@github.com>
Mon, 2 Sep 2024 09:08:19 +0000 (17:08 +0800)
packages/reactivity/__tests__/ref.spec.ts

index 56863471ad512ae694e4c1a1e93ea95aa8f7e6fe..7976a5373baf6edd4ad7f0f83618b203eee47a82 100644 (file)
@@ -46,26 +46,22 @@ describe('reactivity/ref', () => {
   it('ref wrapped in reactive should not track internal _value access', () => {
     const a = ref(1)
     const b = reactive(a)
-    let calls = 0
     let dummy
-
-    effect(() => {
-      calls++
+    const fn = vi.fn(() => {
       dummy = b.value // this will observe both b.value and a.value access
     })
-    expect(calls).toBe(1)
+    effect(fn)
+    expect(fn).toHaveBeenCalledTimes(1)
     expect(dummy).toBe(1)
 
     // mutating a.value should only trigger effect once
-    calls = 0
     a.value = 3
-    expect(calls).toBe(1)
+    expect(fn).toHaveBeenCalledTimes(2)
     expect(dummy).toBe(3)
 
     // mutating b.value should trigger the effect twice. (once for a.value change and once for b.value change)
-    calls = 0
     b.value = 5
-    expect(calls).toBe(2)
+    expect(fn).toHaveBeenCalledTimes(4)
     expect(dummy).toBe(5)
   })