Skip to content

Commit 7a4ddea

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

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
'no-console': 0,
2121
'prettier/prettier': 'error',
2222
'linebreak-style': ['error', 'unix'],
23+
'promise/no-callback-in-promise': 0,
2324
indent: ['error', 2],
2425
semi: ['error', 'never'],
2526
quotes: ['error', 'single'],

src/components/ion-vue-router.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
leave(el, done) {
9292
const promise = this.transition(this.enteringEl, el)
9393
if (!promise) return done()
94-
promise.finally(() => done()).catch(err => console.error(err))
94+
promise.then(() => done(true)).catch(err => console.error(err))
9595
},
9696
enter(el, done) {
9797
done()

test/ion-vue-router.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,38 @@ describe('IonVueRouter', () => {
5656
expect(component.animated).toBeTruthy()
5757
expect(component.name).toBe('default')
5858
})
59+
60+
it('Catches back button click event', () => {
61+
const constructor = Vue.extend(IonVueRouter)
62+
const component = new constructor()
63+
component.catchIonicGoBack({})
64+
})
65+
66+
it('Transitions correctly', () => {
67+
expect.assertions(4)
68+
69+
const constructor = Vue.extend(IonVueRouter)
70+
const component = new constructor({ router: new Router() })
71+
72+
component.$refs.ionRouterOutlet = mockIonRouterOutlet()
73+
expect(component.transition()).toBeFalsy()
74+
75+
component.enteringEl = document.createElement('div')
76+
component.leave(document.createElement('h1'), res => {
77+
expect(res).toBeTruthy()
78+
})
79+
80+
component.leave(null, res => {
81+
expect(res).toBeInstanceOf(Error)
82+
})
83+
84+
component
85+
.transition(document.createElement('div'), document.createElement('h1'))
86+
.then(res => {
87+
return expect(res).toBeTruthy()
88+
})
89+
.catch(err => console.error(err))
90+
})
5991
})
6092

6193
function Toolbar() {
@@ -105,3 +137,17 @@ function Page() {
105137
</ion-page>`,
106138
})
107139
}
140+
141+
function mockIonRouterOutlet() {
142+
return {
143+
componentOnReady() {
144+
return new Promise(resolve => {
145+
return resolve({
146+
commit() {
147+
return true
148+
},
149+
})
150+
})
151+
},
152+
}
153+
}

0 commit comments

Comments
 (0)