-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Nx Angular: Jest encountered an unexpected token #11888
Comments
you'll have to transform any esm code to be used within jest since jest only uses cjs. i.e. /* eslint-disable */
export default {
displayName: 'core',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
coverageDirectory: '../../coverage/libs/core',
transform: {
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$|lodash-es)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
}; there is a chance that lodash comes with a cjs version, if so you can just use the moduleNameMapper to tell jest to always use that version. |
It has caused a lot of problems with my app. |
@ibrahim-azez what problems are you referencing? this is the default config that is generated (minus the lodash addition). If it is now working and you are having a separate issue please close this issue and open a new one with other issues you're running into. |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
I have jest configured in package.json
And I have configured babel.config.js
I am getting this error while running the tests -
If i remove the import of package @shopify/polaris-viz, the tests run successfully. |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
My main app is giving me this error after testing.
I have seen this issue before but did not find any solution to it.
The failing message:
And my testing code for the main application is the following:
My main application jest config
And the default jest config for the whole workspace
My core library is doing testing just fine
the jest config for the core library:
Related Issues:
#10100
Expected Behavior
Steps to Reproduce
Failure Logs
Environment
The text was updated successfully, but these errors were encountered: