]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(effect): add test for nested stopped effect (#417)
authorJiZhi <471695625@qq.com>
Wed, 30 Oct 2019 15:36:17 +0000 (23:36 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 30 Oct 2019 15:36:17 +0000 (11:36 -0400)
packages/reactivity/__tests__/effect.spec.ts

index 38ec27b4ba9c19a38637d774636af342f167b093..0e09e2e6d4248706861a5a62063705b3d3697ca5 100644 (file)
@@ -686,6 +686,28 @@ describe('reactivity/effect', () => {
     expect(onStop).toHaveBeenCalled()
   })
 
+  it('stop: a stopped effect is nested in a normal effect', () => {
+    let dummy
+    const obj = reactive({ prop: 1 })
+    const runner = effect(() => {
+      dummy = obj.prop
+    })
+    stop(runner)
+    obj.prop = 2
+    expect(dummy).toBe(1)
+
+    // observed value in inner stopped effect
+    // will track outer effect as an dependency
+    effect(() => {
+      runner()
+    })
+    expect(dummy).toBe(2)
+
+    // notify outer effect to run
+    obj.prop = 3
+    expect(dummy).toBe(3)
+  })
+
   it('markNonReactive', () => {
     const obj = reactive({
       foo: markNonReactive({