import Vue from 'vue' describe('Options lifecyce hooks', () => { let spy beforeEach(() => { spy = jasmine.createSpy('hook') }) describe('beforeCreate', () => { it('should allow modifying options', () => { const vm = new Vue({ data: { a: 1 }, beforeCreate () { spy() expect(this.a).toBeUndefined() this.$options.computed = { b () { return this.a + 1 } } } }) expect(spy).toHaveBeenCalled() expect(vm.b).toBe(2) }) }) describe('created', () => { it('should have completed observation', () => { new Vue({ data: { a: 1 }, created () { expect(this.a).toBe(1) spy() } }) expect(spy).toHaveBeenCalled() }) }) describe('beforeMount', () => { it('should not have mounted', () => { const vm = new Vue({ beforeMount () { spy() expect(this._isMounted).toBe(false) expect(this.$el).toBeUndefined() // due to empty mount expect(this._vnode).toBeNull() expect(this._watcher).toBeNull() } }) expect(spy).not.toHaveBeenCalled() vm.$mount() expect(spy).toHaveBeenCalled() }) }) describe('mounted', () => { it('should have mounted', () => { const vm = new Vue({ template: '
', mounted () { spy() expect(this._isMounted).toBe(true) expect(this.$el.tagName).toBe('DIV') expect(this._vnode.tag).toBe('div') } }) expect(spy).not.toHaveBeenCalled() vm.$mount() expect(spy).toHaveBeenCalled() }) it('should mount child parent in correct order', () => { const calls = [] new Vue({ template: '