Преглед на файлове

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)
     })
   })
+
+  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()
+  })
 })