Преглед изворни кода

test(reactivity): use vitest fn instead of counting manually (#8476)

zqran пре 2 година
родитељ
комит
7c2e44ff5f
1 измењених фајлова са 5 додато и 6 уклоњено
  1. 5 6
      packages/reactivity/__tests__/ref.spec.ts

+ 5 - 6
packages/reactivity/__tests__/ref.spec.ts

@@ -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', () => {