Jest Testing Fails
parsable-mhalum opened this issue · comments
Hey @parsable-mhalum,
I need some more information to try and reproduce this:
- react-native-size-matters version
- react-native version
- jest version
- jest config
- any babel config (or similar tool if something else is used)
- test example
And best will be to provide some repo that reproduces the issue.
hi @nirsky,
Here are the information that you need:
"react-native-size-matters": "^0.4.0",
"react-native": "0.63.4",
"jest": "^25.1.0",
and here is the repo
https://github.com/martin9908/mytinerary
Seems like the issue is related to the fact that react-native-size-matters
is shipped uncompiled (common for react-native libs).
Related StackOverflow answer - https://stackoverflow.com/a/55803188/2546475
Jest offers a solution - https://jestjs.io/docs/tutorial-react-native#transformignorepatterns-customization
I was able to get it work with the following jest config:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!(@react-native|react-native|react-native-size-matters)/)"
]
}
Let me know if this works for you.
I'll also consider shipping this lib pre-complied.
I had issues compiling this project to commonJS due to babel-plugin-dotenv-import
not working in commonJS.
So I'm gonna leave the solution as-is and close this issue.
Seems like the issue is related to the fact that
react-native-size-matters
is shipped uncompiled (common for react-native libs). Related StackOverflow answer - https://stackoverflow.com/a/55803188/2546475 Jest offers a solution - https://jestjs.io/docs/tutorial-react-native#transformignorepatterns-customizationI was able to get it work with the following jest config:
"jest": { "preset": "react-native", "transformIgnorePatterns": [ "node_modules/(?!(@react-native|react-native|react-native-size-matters)/)" ] }Let me know if this works for you. I'll also consider shipping this lib pre-complied.
This doesn't resolve the issue, I'm still getting the error
i use this jest.config.js
for patched react-native-size-matters/extend
, and it's working now for me:
/** @type {import('jest').Config} */
const config = {
verbose: true,
preset: "react-native",
setupFiles: ["<rootDir>/jest.setup.js"],
setupFilesAfterEnv: ["@testing-library/react-native/extend-expect"],
transformIgnorePatterns: [
"node_modules/(?!(@react-native|react-native|react-native-size-matters(?!/extend)))/",
],
};
module.exports = config;