From 2ce08d63cc527968af6fcbb2d5df7f752f27a73b Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 1 Jun 2016 17:15:25 -0400 Subject: [PATCH] test transition on child components --- .../features/transition/transition.spec.js | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/unit/features/transition/transition.spec.js b/test/unit/features/transition/transition.spec.js index ae60ee27..ecb5c2db 100644 --- a/test/unit/features/transition/transition.spec.js +++ b/test/unit/features/transition/transition.spec.js @@ -311,6 +311,35 @@ if (!isIE9) { }).then(done) }) + it('no transition detected', done => { + const enterSpy = jasmine.createSpy('enter') + const leaveSpy = jasmine.createSpy('leave') + const vm = new Vue({ + template: '
foo
', + data: { ok: true }, + transitions: { + nope: { + enter: enterSpy, + leave: leaveSpy + } + } + }).$mount(el) + + vm.ok = false + waitForUpdate(() => { + expect(leaveSpy).toHaveBeenCalled() + expect(vm.$el.innerHTML).toBe('
foo
') + }).thenWaitFor(nextFrame).then(() => { + expect(vm.$el.innerHTML).toBe('') + vm.ok = true + }).then(() => { + expect(enterSpy).toHaveBeenCalled() + expect(vm.$el.innerHTML).toBe('
foo
') + }).thenWaitFor(nextFrame).then(() => { + expect(vm.$el.innerHTML).toMatch(/foo<\/div>/) + }).then(done) + }) + it('enterCancelled', done => { const spy = jasmine.createSpy('enterCancelled') const vm = new Vue({ @@ -475,6 +504,36 @@ if (!isIE9) { expect(vm.$el.childNodes[0].getAttribute('class')).toBe('test') }).then(done) }) + + it('transition on child components', done => { + const vm = new Vue({ + template: '
', + data: { ok: true }, + components: { + test: { + template: '
foo
' // test transition override from parent + } + } + }).$mount(el) + + // should not apply transition on initial render by default + expect(vm.$el.innerHTML).toBe('
foo
') + vm.ok = false + waitForUpdate(() => { + expect(vm.$el.children[0].className).toBe('test v-leave') + }).thenWaitFor(nextFrame).then(() => { + expect(vm.$el.children[0].className).toBe('test v-leave-active') + }).thenWaitFor(timeout(duration + 10)).then(() => { + expect(vm.$el.children.length).toBe(0) + vm.ok = true + }).then(() => { + expect(vm.$el.children[0].className).toBe('test v-enter') + }).thenWaitFor(nextFrame).then(() => { + expect(vm.$el.children[0].className).toBe('test v-enter-active') + }).thenWaitFor(timeout(duration + 10)).then(() => { + expect(vm.$el.children[0].className).toBe('test') + }).then(done) + }) }) }