index.mjs causes jest to throw (regression in v1.0.4)
See original GitHub issueReproduction
A CLI app using Jest and createRouterMock in a unit test will throw when upgrading to v1.0.4 with:
/Users/cedric/Code/ninjasquad/vue-ebook/book-tests/node_modules/vue-router-mock/dist/index.mjs:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { createRouter, createMemoryHistory, START_LOCATION, routerKey, routeLocationKey, routerViewLocationKey, matchedRouteKey, RouterView, RouterLink } from 'vue-router';
^^^^^^
SyntaxError: Cannot use import statement outside a module
1 | import { flushPromises, mount } from '@vue/test-utils';
> 2 | import { createRouterMock, injectRouterMock } from 'vue-router-mock';
This is because the main file switched to the mjs format, which is great for Vite but not ideal for Jest.
Expected behavior
Jest tests should still work
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Using Jest to test a function which should throw an error, but ...
My function is in index.js, and the test is in check.test.js. I am not sure what caused this issue. Inside of index.js:
Read more >Changelog - Cypress Documentation
Fixed an 11.0.0 regression where using custom reporters would cause Cypress to throw a 'Cannot find module' error. Fixes #24607; Fixed testIsolation ...
Read more >Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >How To Test a React App with Jest and React Testing Library
queryBy* (used when testing the absence of an element without throwing an error); findBy* (used when testing asynchronous code). Each query type ...
Read more >Jest explicitly or arbitrarily force fail() a test - Code with Hugo
js:10:19) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.883s Ran all test suites matching /src\/fail-throws...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Totally! Published a new verison
Amazing @posva !
Just one little comment, do you think it makes sense to use the
exportsfield to expose both files?Thanks a lot! 😄