Skip to content

Commit 3838e96

Browse files
committed
test for hook merging
1 parent 8c411fb commit 3838e96

File tree

4 files changed

+115
-2
lines changed

4 files changed

+115
-2
lines changed

test/unit/lib/pipeline-test-util.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ exports.test = function (configs, cb) {
2424
var config = configs[route]
2525
Object.keys(config).forEach(function (hook) {
2626
var fn = config[hook]
27+
if (Array.isArray(fn) || hook === 'mixins') {
28+
return
29+
}
2730
if (fn.length) {
2831
config[hook] = function (transition) {
2932
var event = route + '.' + hook
@@ -84,12 +87,15 @@ exports.test = function (configs, cb) {
8487
'/data/:msg': {
8588
component: {
8689
route: configs.data,
90+
mixins: configs.data && configs.data.mixins,
8791
template:
8892
'<span v-if="$loadingRouteData">loading...</span>' +
89-
'<span v-if="!$loadingRouteData">{{msg}}</span>',
93+
'<span v-if="!$loadingRouteData">{{msg}}{{otherMsg}}{{thirdMsg}}</span>',
9094
data: function () {
9195
return {
92-
msg: 'default'
96+
msg: 'default',
97+
otherMsg: '',
98+
thirdMsg: ''
9399
}
94100
}
95101
}

test/unit/specs/pipeline/activate.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,34 @@ describe('activate', function () {
168168
done()
169169
})
170170
})
171+
172+
it('multiple', function (done) {
173+
var calls = []
174+
test({
175+
a: {
176+
activate: [
177+
function (transition) {
178+
calls.push(1)
179+
setTimeout(function () {
180+
transition.next()
181+
}, wait)
182+
},
183+
function () {
184+
calls.push(2)
185+
return new Promise(function (resolve) {
186+
setTimeout(resolve, wait)
187+
})
188+
}
189+
]
190+
}
191+
}, function (router, _, emitter) {
192+
router.go('/a')
193+
expect(router.app.$el.textContent).toBe('')
194+
setTimeout(function () {
195+
assertCalls(calls, [1, 2])
196+
expect(router.app.$el.textContent).toBe('A ')
197+
done()
198+
}, wait * 3)
199+
})
200+
})
171201
})

test/unit/specs/pipeline/data.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,49 @@ describe('data', function () {
196196
}, wait * 2)
197197
})
198198
})
199+
200+
it('multiple data hooks', function (done) {
201+
test({
202+
data: {
203+
data: [
204+
function (transition) {
205+
return {
206+
msg: new Promise(function (resolve) {
207+
setTimeout(function () {
208+
resolve(transition.to.params.msg)
209+
}, wait)
210+
})
211+
}
212+
},
213+
function (transition) {
214+
return new Promise(function (resolve) {
215+
setTimeout(function () {
216+
resolve({
217+
otherMsg: ' ' + transition.to.params.msg + '2'
218+
})
219+
}, wait)
220+
})
221+
}
222+
],
223+
mixins: [
224+
{
225+
route: {
226+
data: function (transition) {
227+
transition.next({
228+
thirdMsg: ' ' + transition.to.params.msg + '3'
229+
})
230+
}
231+
}
232+
}
233+
]
234+
}
235+
}, function (router, calls, emitter) {
236+
router.go('/data/hello')
237+
expect(router.app.$el.textContent).toBe('loading...')
238+
setTimeout(function () {
239+
expect(router.app.$el.textContent).toBe('hello hello2 hello3')
240+
done()
241+
}, wait * 3)
242+
})
243+
})
199244
})

test/unit/specs/pipeline/deactivate.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,36 @@ describe('deactivate', function () {
154154
}, wait * 2)
155155
})
156156
})
157+
158+
it('multiple', function (done) {
159+
var calls = []
160+
test({
161+
a: {
162+
deactivate: [
163+
function (transition) {
164+
calls.push(1)
165+
setTimeout(function () {
166+
transition.next()
167+
}, wait)
168+
},
169+
function () {
170+
calls.push(2)
171+
return new Promise(function (resolve) {
172+
setTimeout(resolve, wait)
173+
})
174+
}
175+
]
176+
}
177+
}, function (router, _, emitter) {
178+
router.go('/a')
179+
expect(router.app.$el.textContent).toBe('A ')
180+
router.go('/b')
181+
expect(router.app.$el.textContent).toBe('A ')
182+
setTimeout(function () {
183+
assertCalls(calls, [1, 2])
184+
expect(router.app.$el.textContent).toBe('')
185+
done()
186+
}, wait * 3)
187+
})
188+
})
157189
})

0 commit comments

Comments
 (0)