Skip to content

Commit ecda8a4

Browse files
Add initial ion-vue-router test. Improve jest config
1 parent e10c8e7 commit ecda8a4

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
22
testURL: 'http://localhost/',
33
moduleFileExtensions: ['js', 'vue'],
4+
moduleNameMapper: {
5+
'^vue$': 'vue/dist/vue.common.js',
6+
},
47
transform: {
58
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
69
'.*\\.(vue)$': '<rootDir>/node_modules/jest-vue-preprocessor',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"prod": "NODE_ENV=production rollup -c ./build/rollup.config.js --configProd",
4242
"release": "bash ./build/release.sh",
4343
"lint": "eslint src/**/* build/*.js test/**/*",
44-
"test": "jest --coverage",
45-
"test:node": "jest --coverage --env=node"
44+
"test": "jest --coverage --verbose",
45+
"test:node": "jest --coverage --verbose --env=node"
4646
},
4747
"devDependencies": {
4848
"babel-jest": "^23.4.2",

test/ion-vue-router.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Vue from 'vue'
2+
import Router from '../src/router.js'
3+
import IonVueRouter from '../src/components/ion-vue-router.vue'
4+
5+
describe('IonVueRouter', () => {
6+
it('Renders correctly', () => {
7+
Vue.use(Router)
8+
Vue.config.ignoredElements.push(/^ion-/)
9+
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()
18+
19+
app.$router.push('/foo')
20+
app.$router.back()
21+
22+
expect(app.$el.textContent).toBe('foo')
23+
})
24+
25+
it('Sets the default data correctly', () => {
26+
expect(typeof IonVueRouter.data).toBe('function')
27+
expect(IonVueRouter.data()).toMatchObject({
28+
leavingEl: null,
29+
enteringEl: null,
30+
})
31+
})
32+
33+
it('Sets the default props correctly', () => {
34+
const constructor = Vue.extend(IonVueRouter)
35+
const component = new constructor()
36+
expect(component.bindCss).toBeFalsy()
37+
expect(component.animated).toBeTruthy()
38+
expect(component.name).toBe('default')
39+
})
40+
})

test/router.node.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22

3-
describe('asd', () => {
4-
it('qqq', () => {
3+
describe('Router node', () => {
4+
it('Sets globals correctly', () => {
55
window.Vue = undefined
66
global.Vue = Vue
77
require('../src/router.js')

0 commit comments

Comments
 (0)