Skip to content

Commit ed762f8

Browse files
committed
fix coverage for svg transitions
1 parent e6ad4ee commit ed762f8

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

src/parsers/template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ var hasTextareaCloneBug = (function () {
200200
*/
201201

202202
export function cloneNode (node) {
203+
/* istanbul ignore if */
203204
if (!node.querySelectorAll) {
204205
return node.cloneNode()
205206
}

test/unit/specs/transition/transition_spec.js

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ if (!_.isIE9) {
121121

122122
describe('CSS transitions', function () {
123123
var vm, el, op, cb, hooks
124-
beforeEach(function (done) {
124+
beforeEach(function () {
125125
el = document.createElement('div')
126126
el.textContent = 'hello'
127127
vm = new Vue({ el: el })
@@ -138,7 +138,9 @@ if (!_.isIE9) {
138138
}
139139
// !IMPORTANT!
140140
// this ensures we force a layout for every test.
141-
_.nextTick(done)
141+
/* eslint-disable no-unused-vars */
142+
var f = document.body.offsetHeight
143+
/* eslint-enable no-unused-vars */
142144
})
143145

144146
afterEach(function () {
@@ -221,12 +223,42 @@ if (!_.isIE9) {
221223
})
222224
})
223225

226+
it('transition enter for svg', function (done) {
227+
el.innerHTML = '<svg><circle cx="0" cy="0" r="10"></circle></svg>'
228+
var svg = el.querySelector('svg')
229+
var circle = el.querySelector('circle')
230+
svg.removeChild(circle)
231+
circle.__v_trans = new Transition(circle, 'test', hooks, vm)
232+
// inline style
233+
circle.style.transition =
234+
circle.style.WebkitTransition = 'opacity ' + duration + ' ease'
235+
transition.applyTransition(circle, 1, function () {
236+
svg.appendChild(circle)
237+
op()
238+
}, vm, cb)
239+
expect(hooks.beforeEnter).toHaveBeenCalled()
240+
expect(hooks.enter).toHaveBeenCalled()
241+
expect(op).toHaveBeenCalled()
242+
expect(cb).not.toHaveBeenCalled()
243+
_.nextTick(function () {
244+
expect(circle.getAttribute('class').indexOf('test-enter') > -1).toBe(false)
245+
expect(hooks.afterEnter).not.toHaveBeenCalled()
246+
_.on(circle, _.transitionEndEvent, function () {
247+
expect(cb).toHaveBeenCalled()
248+
expect(hooks.afterEnter).toHaveBeenCalled()
249+
done()
250+
})
251+
})
252+
})
253+
224254
it('transition leave', function (done) {
225255
el.__v_trans = new Transition(el, 'test', hooks, vm)
226256
// cascaded class style
227257
el.classList.add('test')
228258
// force a layout here so the transition can be triggered
259+
/* eslint-disable no-unused-vars */
229260
var f = el.offsetHeight
261+
/* eslint-enable no-unused-vars */
230262
transition.applyTransition(el, -1, op, vm, cb)
231263
expect(hooks.beforeLeave).toHaveBeenCalled()
232264
expect(hooks.leave).toHaveBeenCalled()
@@ -243,7 +275,32 @@ if (!_.isIE9) {
243275
done()
244276
})
245277
})
246-
return f
278+
})
279+
280+
it('transition leave for svg', function (done) {
281+
el.innerHTML = '<svg><circle cx="0" cy="0" r="10" class="test"></circle></svg>'
282+
var circle = el.querySelector('circle')
283+
circle.__v_trans = new Transition(circle, 'test', hooks, vm)
284+
// force a layout here so the transition can be triggered
285+
/* eslint-disable no-unused-vars */
286+
var f = el.offsetHeight
287+
/* eslint-enable no-unused-vars */
288+
transition.applyTransition(circle, -1, op, vm, cb)
289+
expect(hooks.beforeLeave).toHaveBeenCalled()
290+
expect(hooks.leave).toHaveBeenCalled()
291+
_.nextTick(function () {
292+
expect(op).not.toHaveBeenCalled()
293+
expect(cb).not.toHaveBeenCalled()
294+
expect(hooks.afterLeave).not.toHaveBeenCalled()
295+
expect(circle.getAttribute('class').indexOf('test-leave') > -1).toBe(true)
296+
_.on(circle, _.transitionEndEvent, function () {
297+
expect(op).toHaveBeenCalled()
298+
expect(cb).toHaveBeenCalled()
299+
expect(circle.getAttribute('class').indexOf('test-leave') > -1).toBe(false)
300+
expect(hooks.afterLeave).toHaveBeenCalled()
301+
done()
302+
})
303+
})
247304
})
248305

249306
it('animation enter', function (done) {

0 commit comments

Comments
 (0)