Hey guys,
I appreciate your work!
I am currently configuring my project to work with Jest I know this might be beyond your problem but I came across this error when I run npm run test (I am using jest, of course) in my project.
I could probably use jest.mock but I prefer cleaner solution. Any suggestion?
FYI, below is the error I got.
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot
parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• 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/en/configuration.html
Details:
/Users/{my_path}/node_modules/@invertase/react-native-apple-authentication/lib/index.js:18
import version from './version';
^^^^^^
SyntaxError: Unexpected token import
I ignore it during jest transform like so
(base) mike@kunashir:~/work/Kullki/ksocialscore/packages/public-app (onboarding) % cat jest.config.js
module.exports = {
rootDir: './dist/tests/rnapp/js',
roots: ['<rootDir>'],
// transform: {
// '^.+\\.tsx?$': 'ts-jest',
// },
transformIgnorePatterns: [
'node_modules/(?!@react-native-community/google-signin|react-native|reactxp-webview|react-pose-core|animated-pose|@react-native-community/async-storage|@invertase/react-native-apple-authentication)',
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
preset: 'react-native',
testEnvironment: 'jsdom',
collectCoverage: true,
setupFilesAfterEnv: [
'./__mocks__/mockFirebase.js',
'./__mocks__/mockReactNative.js',
'./__mocks__/mockAsyncStorage.js',
],
};
// module.exports = {
// testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
// };
(base) mike@kunashir:~/work/Kullki/ksocialscore/packages/public-app (onboarding) %
We'll accept PRs any time but this isn't actionable I don't think, would be user driven if there are changes as maintainers aren't having issues at the moment
Most helpful comment
I ignore it during jest transform like so