I am trying to use Jest and only test the rendering, here's my test file:
import "react-native";
import React from "react";
import App from"../src/Root/";
import { create } from "react-test-renderer";
describe("App", () => {
const tree = create(<App />).toJSON();
it("renders correctly", () => {
expect(tree).toMatchSnapshot();
});
});
when I run yarn test, I got an error
Error message:
/dic/node_modules/react-native/Libraries/polyfills/error-guard.js:14
type ErrorHandler = (error: mixed, isFatal: boolean) => void;
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/react-native/jest/setup.js:16:6)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.128 s
babel.config.js
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
plugins: [["module:react-native-dotenv"], "react-native-reanimated/plugin"],
};
jest.config.js
module.exports = {
preset: "react-native",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
transform: {
"^.+\\.(js|jsx)$": "babel-jest",
"^.+\\.(ts|tsx)$": "ts-jest",
},
transformIgnorePatterns: [
"node_modules/(?!(jest-)?@react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)",
],
};
I've followed tons of solutions attempt online but I can't find that fit to my problem, including adding react-native to transformIgnorePatterns