Closed vkuprin closed 1 month ago
Looks like Jest/Babel config problem. Please compare your setup with our example app: https://github.com/callstack/react-native-testing-library/tree/main/examples/basic
You have quite complex Babel config so my advice would be to start gradually moving your Babel & Jest config to the example app and checking which rules (added or removed) start causing the error. This way you should be able to narrow down your issue and hopefully fix it. Good luck! 🍀
Was able to fix the problem by reusing the example from: https://github.com/callstack/react-native-testing-library/tree/main/examples/basic
jest.setup.ts
import "@testing-library/react-native/extend-expect";
jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
jest.mock("react-native-webrtc");
jest.mock("node-fetch", () => require("jest-fetch-mock"));
jest.config.js
module.exports = {
preset: "@testing-library/react-native",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
setupFilesAfterEnv: ["<rootDir>/jestSetup.ts"],
};
babel.config.js
module.exports = {
presets: ["module:@react-native/babel-preset"],
plugins: [
"react-native-reanimated/plugin",
"babel-plugin-styled-components",
[
"module-resolver",
{
root: ["./src"],
alias: {},
},
],
],
};
Seems the issue was with conflicting babel presets
Description
I am encountering an "Unexpected token 'export'" error when running Jest tests for a React Native project using React
Native Testing Library. This issue appears to be related to the transformation of ES6 module syntax in certain dependencies.
package.json
babel.config.js
jest.config.js
jestSetup.ts
What you did:
Running Jest tests for a React Native project with the configuration and code provided above.
Unexpected token 'export'
There seems to be an issue with configuration that prevents React Native Testing Library from working correctly.
Reproduction:
A minimal reproduction can be created by setting up a new React Native project with the provided Babel and Jest configurations, and attempting to run the example test file.
Problem description:
The current behavior is problematic because Jest is unable to process the ES6 module syntax (e.g., export) in certain dependencies, causing the tests to fail.