Skip to content

Commit 429e61b

Browse files
Improve ion-vue-router rendering tests
1 parent ecda8a4 commit 429e61b

File tree

2 files changed

+85
-14
lines changed

2 files changed

+85
-14
lines changed

src/components/ion-vue-router.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export default {
6060
transition(enteringEl, leavingEl) {
6161
const ionRouterOutlet = this.$refs.ionRouterOutlet
6262
63+
if (typeof ionRouterOutlet.componentOnReady === 'undefined') {
64+
return
65+
}
66+
6367
if (!enteringEl || enteringEl === leavingEl) {
6468
return
6569
}

test/ion-vue-router.spec.js

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,42 @@ import Router from '../src/router.js'
33
import IonVueRouter from '../src/components/ion-vue-router.vue'
44

55
describe('IonVueRouter', () => {
6-
it('Renders correctly', () => {
7-
Vue.use(Router)
8-
Vue.config.ignoredElements.push(/^ion-/)
6+
Vue.use(Router)
7+
Vue.config.ignoredElements.push(/^ion-/)
98

10-
const app = new Vue({
11-
render(h) {
12-
return h('ion-vue-router')
13-
},
14-
router: new Router({
15-
routes: [{ path: '/', component: { template: '<h1>foo</h1>' } }],
16-
}),
17-
}).$mount()
9+
const app = new Vue({
10+
components: { Toolbar: Toolbar() },
11+
render(h) {
12+
return h('ion-vue-router')
13+
},
14+
router: new Router({
15+
mode: 'abstract',
16+
routes: [{ path: '/', component: Home() }, { path: '/page', component: Page() }],
17+
}),
18+
}).$mount()
19+
20+
it('Renders the home route correctly', done => {
21+
app.$router.push('/')
22+
setTimeout(() => {
23+
expect(app.$el.textContent.trim()).toBe('Home Go to page')
24+
done()
25+
}, 1)
26+
})
1827

19-
app.$router.push('/foo')
20-
app.$router.back()
28+
it('Renders the page route correctly', done => {
29+
app.$router.push('/page')
30+
setTimeout(() => {
31+
expect(app.$el.textContent.trim()).toBe('Page Go home')
32+
done()
33+
}, 1)
34+
})
2135

22-
expect(app.$el.textContent).toBe('foo')
36+
it('Renders back route correctly', done => {
37+
app.$router.go(-1)
38+
setTimeout(() => {
39+
expect(app.$el.textContent.trim()).toBe('Home Go to page')
40+
done()
41+
}, 1)
2342
})
2443

2544
it('Sets the default data correctly', () => {
@@ -38,3 +57,51 @@ describe('IonVueRouter', () => {
3857
expect(component.name).toBe('default')
3958
})
4059
})
60+
61+
function Toolbar() {
62+
return Vue.component('Toolbar', {
63+
name: 'Toolbar',
64+
props: {
65+
backURL: { type: String, default: '' },
66+
title: { type: String, default: '' },
67+
},
68+
template: `
69+
<ion-header>
70+
<ion-toolbar>
71+
<ion-buttons slot="start">
72+
<ion-back-button :default-href="backURL"/>
73+
</ion-buttons>
74+
<ion-title>{{ title }}</ion-title>
75+
</ion-toolbar>
76+
</ion-header>`,
77+
})
78+
}
79+
80+
function Home() {
81+
return Vue.component('Home', {
82+
template: `
83+
<ion-page class="ion-page">
84+
<toolbar title="Home"/>
85+
<ion-content class="ion-content" padding>
86+
<router-link to="/page">Go to page</router-link>
87+
</ion-content>
88+
</ion-page>`,
89+
})
90+
}
91+
92+
function Page() {
93+
return Vue.component('Page', {
94+
methods: {
95+
goHome() {
96+
this.$router.back()
97+
},
98+
},
99+
template: `
100+
<ion-page class="ion-page">
101+
<toolbar title="Page"/>
102+
<ion-content class="ion-content" padding>
103+
<ion-button @click="goHome">Go home</ion-button>
104+
</ion-content>
105+
</ion-page>`,
106+
})
107+
}

0 commit comments

Comments
 (0)