From 58a4b5a3563e8bf73426d4263df73be5336f7a18 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Tue, 17 Mar 2020 15:15:57 +0100 Subject: [PATCH] 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 --- src/__tests__/vue-router-mocha.js | 16 ++++++++++++++++ src/vue-testing-library.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/vue-router-mocha.js diff --git a/src/__tests__/vue-router-mocha.js b/src/__tests__/vue-router-mocha.js new file mode 100644 index 00000000..6cb0fa4f --- /dev/null +++ b/src/__tests__/vue-router-mocha.js @@ -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"), + ) +}) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index 3dbabde4..3aa4041d 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -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,