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

test case for lifecycle hook events

Evan You пре 9 година
родитељ
комит
7f260e1185
1 измењених фајлова са 25 додато и 0 уклоњено
  1. 25 0
      test/unit/features/options/lifecycle.spec.js

+ 25 - 0
test/unit/features/options/lifecycle.spec.js

@@ -193,4 +193,29 @@ describe('Options lifecyce hooks', () => {
       expect(spy.calls.count()).toBe(1)
       expect(spy.calls.count()).toBe(1)
     })
     })
   })
   })
+
+  it('should emit hook events', () => {
+    const created = jasmine.createSpy()
+    const mounted = jasmine.createSpy()
+    const destroyed = jasmine.createSpy()
+    const vm = new Vue({
+      render () {},
+      beforeCreate () {
+        this.$on('hook:created', created)
+        this.$on('hook:mounted', mounted)
+        this.$on('hook:destroyed', destroyed)
+      }
+    })
+
+    expect(created).toHaveBeenCalled()
+    expect(mounted).not.toHaveBeenCalled()
+    expect(destroyed).not.toHaveBeenCalled()
+
+    vm.$mount()
+    expect(mounted).toHaveBeenCalled()
+    expect(destroyed).not.toHaveBeenCalled()
+
+    vm.$destroy()
+    expect(destroyed).toHaveBeenCalled()
+  })
 })
 })