forked from ModusCreateOrg/ionic-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathion-vue-router-transitionless.spec.js
43 lines (35 loc) · 1.11 KB
/
ion-vue-router-transitionless.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
import Vue from 'vue'
import Router from '../src/router.js'
import IonVueRouterTransitionless from '../src/components/ion-vue-router-transitionless.vue'
Vue.use(Router)
describe('IonVueRouter', () => {
it('Catches back button click event', () => {
const constructor = Vue.extend(IonVueRouterTransitionless)
const component = new constructor({ router: new Router({ mode: 'abstract' }) })
expect(component.catchIonicGoBack({})).toBeFalsy()
component.$router.push('/')
component.$router.push('/foo')
expect(component.$route.fullPath).toBe('/foo')
// Go back
component.catchIonicGoBack(mockBackEvent('/'))
expect(component.$route.fullPath).toBe('/')
// Should not go back
component.catchIonicGoBack(mockBackEvent())
expect(component.$route.fullPath).toBe('/')
// Go back to default route
component.catchIonicGoBack(mockBackEvent('/bar'))
expect(component.$route.fullPath).toBe('/bar')
})
})
function mockBackEvent(route) {
return {
target: {
closest() {
return {
defaultHref: route,
}
},
},
preventDefault() {},
}
}