Skip to content

Commit 76b0cde

Browse files
committed
test for data hook
1 parent b9386fd commit 76b0cde

File tree

2 files changed

+94
-6
lines changed

2 files changed

+94
-6
lines changed

test/unit/specs/pipeline/data.js

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,90 @@
1+
var testUtils = require('../util')
2+
var test = testUtils.test
3+
var assertCalls = testUtils.assertCalls
4+
15
describe('data', function () {
26

3-
it('initial load', function () {
4-
//
7+
it('initial load', function (done) {
8+
test({
9+
data: {
10+
data: function (transition) {
11+
setTimeout(function () {
12+
transition.next({
13+
msg: transition.to.params.msg
14+
})
15+
}, wait)
16+
}
17+
}
18+
}, function (router, calls) {
19+
router.go('/data/hello')
20+
assertCalls(calls, ['data.data'])
21+
expect(router.app.$el.textContent).toBe('loading...')
22+
setTimeout(function () {
23+
expect(router.app.$el.textContent).toBe('hello')
24+
done()
25+
}, wait)
26+
})
527
})
628

7-
it('reload', function () {
8-
//
29+
it('reload', function (done) {
30+
test({
31+
data: {
32+
data: function (transition) {
33+
setTimeout(function () {
34+
transition.next({
35+
msg: transition.to.params.msg
36+
})
37+
}, wait)
38+
}
39+
}
40+
}, function (router, calls) {
41+
router.go('/data/hello')
42+
assertCalls(calls, ['data.data'])
43+
expect(router.app.$el.textContent).toBe('loading...')
44+
setTimeout(function () {
45+
expect(router.app.$el.textContent).toBe('hello')
46+
router.go('/data/reload')
47+
assertCalls(calls, ['data.data', 'data.data'])
48+
router.app.$nextTick(function () {
49+
expect(router.app.$el.textContent).toBe('loading...')
50+
setTimeout(function () {
51+
expect(router.app.$el.textContent).toBe('reload')
52+
done()
53+
}, wait)
54+
})
55+
}, wait)
56+
})
957
})
1058

11-
it('waitForData', function () {
12-
//
59+
it('waitForData', function (done) {
60+
test({
61+
data: {
62+
waitForData: true,
63+
data: function (transition) {
64+
setTimeout(function () {
65+
transition.next({
66+
msg: transition.to.params.msg
67+
})
68+
}, wait)
69+
}
70+
}
71+
}, function (router, calls) {
72+
router.go('/data/hello')
73+
assertCalls(calls, ['data.data'])
74+
expect(router.app.$el.textContent).toBe('')
75+
setTimeout(function () {
76+
expect(router.app.$el.textContent).toBe('hello')
77+
router.go('/data/reload')
78+
assertCalls(calls, ['data.data', 'data.data'])
79+
router.app.$nextTick(function () {
80+
expect(router.app.$el.textContent).toBe('loading...')
81+
setTimeout(function () {
82+
expect(router.app.$el.textContent).toBe('reload')
83+
done()
84+
}, wait)
85+
})
86+
}, wait)
87+
})
1388
})
1489

1590
})

test/unit/specs/util.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ exports.test = function (configs, cb) {
6868
}
6969
}
7070
}
71+
},
72+
'/data/:msg': {
73+
component: {
74+
route: configs.data,
75+
template:
76+
'<span v-if="$loadingRouteData">loading...</span>' +
77+
'<span v-if="!$loadingRouteData">{{msg}}</span>',
78+
data: function () {
79+
return {
80+
msg: 'default'
81+
}
82+
}
83+
}
7184
}
7285
})
7386
router.start(App, el)

0 commit comments

Comments
 (0)