Skip to content

Commit 58a4b5a

Browse files
authored
fix(mocha): allow vue-router creation using mocha (#127)
* fix(#119): allow routes vue-router creation through routes param from both jest and mocha * add test to check vue-router require for mocha users
1 parent 29e37dd commit 58a4b5a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/__tests__/vue-router-mocha.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import '@testing-library/jest-dom'
2+
import {render} from '@testing-library/vue'
3+
4+
import About from './components/Router/About.vue'
5+
6+
const routes = []
7+
test('uses require("vue-router").default when require("vue-router") is undefined (useful for mocha users)', () => {
8+
// Test for fix https://github.com/testing-library/vue-testing-library/issues/119
9+
jest.mock('vue-router', () => {
10+
return undefined
11+
})
12+
13+
expect(() => render(About, {routes})).toThrowError(
14+
new TypeError("Cannot read property 'default' of undefined"),
15+
)
16+
})

src/vue-testing-library.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function render(
3636
}
3737

3838
if (routes) {
39-
const VueRouter = require('vue-router')
39+
const VueRouter = require('vue-router') || require('vue-router').default
4040
localVue.use(VueRouter)
4141
router = new VueRouter({
4242
routes,

0 commit comments

Comments
 (0)