]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactivity/effect): add test for lazy option (#179)
author唐道海 <tangdaohai@outlook.com>
Thu, 10 Oct 2019 14:12:27 +0000 (22:12 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 10 Oct 2019 14:12:27 +0000 (10:12 -0400)
packages/reactivity/__tests__/effect.spec.ts

index 9538e5b896bca3f7d74120157f1aef45dfb82e58..340bf10931e083f1642edc0667fac19ae1591a31 100644 (file)
@@ -505,6 +505,18 @@ describe('reactivity/effect', () => {
     expect(dummy).toBe(1)
   })
 
+  it('lazy', () => {
+    const obj = reactive({ foo: 1 })
+    let dummy
+    const runner = effect(() => (dummy = obj.foo), { lazy: true })
+    expect(dummy).toBe(undefined)
+
+    expect(runner()).toBe(1)
+    expect(dummy).toBe(1)
+    obj.foo = 2
+    expect(dummy).toBe(2)
+  })
+
   it('scheduler', () => {
     let runner: any, dummy
     const scheduler = jest.fn(_runner => {