question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

index.mjs causes jest to throw (regression in v1.0.4)

See original GitHub issue

Reproduction

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
posvacommented, Jan 23, 2022

Totally! Published a new verison

1reaction
pgarciaegidocommented, Jan 23, 2022

Amazing @posva !

Just one little comment, do you think it makes sense to use the exports field to expose both files?

"exports": {
    "require": "./dist/index.cjs",
    "import": "./dist/index.mjs"
  },

Thanks a lot! 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found