-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Jest #11
Comments
Could you please post a reproduction somewhere? Thanks 🙏 |
It seems to be an issue with ts-jest, that seems to expect CJS files: kulshekhar/ts-jest#937 Maybe you could try this? kulshekhar/ts-jest#937 (comment) Closing the issue for now, but please reopen if you can provide a way for me to reproduce it. |
I encounter this issue in a private repo. It's a nextjs typescript app that doesn't use jest.config.js:
Error: pnpm test
> [email protected] test /Users/caffeinum/wallet
> jest
PASS src/utils/parseTokenAmount.test.ts
PASS src/lib/javascript/uniqBy.test.ts
PASS src/utils/preprocessAmount.test.ts
FAIL src/utils/parseFiatAmount.test.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/caffeinum/wallet/node_modules/.pnpm/[email protected]/node_modules/dnum/dist/dnum.js:267
export {
^^^^^^
SyntaxError: Unexpected token 'export'
17 |
18 | export function fiatToTokenAmount({
> 19 | value,
| ^
20 | decimals,
21 | price = 1,
22 | }: {
at Runtime.createScriptFromCode (node_modules/.pnpm/[email protected]/node_modules/jest-runtime/build/index.js:1505:14)
at Object.<anonymous> (src/utils/parseFiatAmount.ts:19:55)
at Object.<anonymous> (src/utils/parseFiatAmount.test.ts:5:26)
Test Suites: 2 failed, 4 passed, 6 total
Tests: 43 passed, 43 total
Snapshots: 0 total
Time: 1.017 s
Ran all test suites.
ELIFECYCLE Test failed. See above for more details. |
Update: I was able to solve this issue by switching from vi.mock("dnum", () => vi.importActual("dnum")); I have added this line to the top of my test file and for some reason this imports the library correctly. I didn't have many tests in my project, so re-writing them was basically finding the right config + adding Another solution we have found is to literally fork Published to: https://www.npmjs.com/package/@sloikaxyz/dnum |
I cannot make my unit tests work.
I get this error:
If I remove the lines of code that exploit dnum the tests work perfectly.
This is my jest.config.js:
The text was updated successfully, but these errors were encountered: