Skip to content

Commit

Permalink
fix(mocha): allow vue-router creation using mocha (#127)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
agualis committed Mar 17, 2020
1 parent 29e37dd commit 58a4b5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/__tests__/vue-router-mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '@testing-library/jest-dom'
import {render} from '@testing-library/vue'

import About from './components/Router/About.vue'

const routes = []
test('uses require("vue-router").default when require("vue-router") is undefined (useful for mocha users)', () => {
// Test for fix https://github.com/testing-library/vue-testing-library/issues/119
jest.mock('vue-router', () => {
return undefined
})

expect(() => render(About, {routes})).toThrowError(
new TypeError("Cannot read property 'default' of undefined"),
)
})
2 changes: 1 addition & 1 deletion src/vue-testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function render(
}

if (routes) {
const VueRouter = require('vue-router')
const VueRouter = require('vue-router') || require('vue-router').default
localVue.use(VueRouter)
router = new VueRouter({
routes,
Expand Down

0 comments on commit 58a4b5a

Please sign in to comment.