]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactivity): use vitest fn instead of counting manually (#8476)
authorzqran <215244947@qq.com>
Tue, 11 Jul 2023 09:37:56 +0000 (17:37 +0800)
committerGitHub <noreply@github.com>
Tue, 11 Jul 2023 09:37:56 +0000 (17:37 +0800)
packages/reactivity/__tests__/ref.spec.ts

index b0ba9d9cb1c3be4ace96864498c3298df3f6c09f..0ee32866da8e4f0d91199763d6c5cd6d1a51733d 100644 (file)
@@ -28,19 +28,18 @@ describe('reactivity/ref', () => {
   it('should be reactive', () => {
     const a = ref(1)
     let dummy
-    let calls = 0
-    effect(() => {
-      calls++
+    const fn = vi.fn(() => {
       dummy = a.value
     })
-    expect(calls).toBe(1)
+    effect(fn)
+    expect(fn).toHaveBeenCalledTimes(1)
     expect(dummy).toBe(1)
     a.value = 2
-    expect(calls).toBe(2)
+    expect(fn).toHaveBeenCalledTimes(2)
     expect(dummy).toBe(2)
     // same value should not trigger
     a.value = 2
-    expect(calls).toBe(2)
+    expect(fn).toHaveBeenCalledTimes(2)
   })
 
   it('should make nested properties reactive', () => {