Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58a4b5a

Browse files
authored
fix(mocha): allow vue-router creation using mocha (testing-library#127)
* fix(testing-library#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‎

Lines changed: 16 additions & 0 deletions
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‎

Lines changed: 1 addition & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /