From b6bcf468156c77a5e75f1615968a894d686e83e9 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Fri, 13 Mar 2020 17:49:41 +0100 Subject: [PATCH 1/2] fix(#119): allow routes vue-router creation through routes param from both jest and mocha --- src/vue-testing-library.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 47168efba57979c347b25c3baaf2dc304871297e Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Tue, 17 Mar 2020 10:01:14 +0100 Subject: [PATCH 2/2] add test to check vue-router require for mocha users --- src/__tests__/vue-router-mocha.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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"), + ) +})