forked from vuejs/vue-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.spec.js
68 lines (63 loc) · 2.05 KB
/
node.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Vue from 'vue'
import VueRouter from '../../../src/index'
Vue.use(VueRouter)
describe('Usage in Node', () => {
it('should be in abstract mode', () => {
const router = new VueRouter()
expect(router.mode).toBe('abstract')
})
it('should be able to navigate without app instance', () => {
const router = new VueRouter({
routes: [
{ path: '/', component: { name: 'foo' }},
{ path: '/bar', component: { name: 'bar' }}
]
})
router.push('/bar')
expect(router.history.current.path).toBe('/bar')
})
it('getMatchedComponents', () => {
const Foo = { name: 'foo' }
const Bar = { name: 'bar' }
const Baz = { name: 'baz' }
const router = new VueRouter({
routes: [
{ path: '/', component: Foo },
{
path: '/bar',
component: Bar,
children: [{ path: 'baz', component: Baz }]
}
]
})
expect(router.getMatchedComponents('/')).toEqual([Foo])
expect(router.getMatchedComponents('/bar/baz')).toEqual([Bar, Baz])
})
it('should navigate through history with same consecutive routes in history stack', () => {
const success = jasmine.createSpy('complete')
const error = jasmine.createSpy('error')
const router = new VueRouter({
routes: [
{ path: '/', component: { name: 'foo' }},
{ path: '/bar', component: { name: 'bar' }}
]
})
router.push('/', success, error)
expect(success).toHaveBeenCalledTimes(1)
expect(error).toHaveBeenCalledTimes(0)
router.push('/bar', success, error)
expect(success).toHaveBeenCalledTimes(2)
expect(error).toHaveBeenCalledTimes(0)
router.push('/', success, error)
expect(success).toHaveBeenCalledTimes(3)
expect(error).toHaveBeenCalledTimes(0)
router.replace('/bar', success, error)
expect(success).toHaveBeenCalledTimes(4)
expect(error).toHaveBeenCalledTimes(0)
spyOn(console, 'warn')
router.back()
expect(router.history.current.path).toBe('/bar')
router.back()
expect(router.history.current.path).toBe('/')
})
})