Skip to content

Commit 24dae84

Browse files
committed
🔧 jest
1 parent 06c8248 commit 24dae84

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

__tests__/__mocks__/index.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-ignore
3+
import mockSafeAreaContext from "react-native-safe-area-context/jest/mock";
4+
5+
// SOURCE: https://stackoverflow.com/questions/66652403/jest-config-is-throwing-type-errorhandler-error-mixed-isfatal-boolean
6+
7+
beforeAll(() => {
8+
// SOURCE: https://stackoverflow.com/questions/50793885/referenceerror-you-are-trying-to-import-a-file-after-the-jest-environment-has#50793993
9+
jest.useFakeTimers();
10+
});
11+
12+
// SOURCE: https://stackoverflow.com/questions/59587799/how-to-resolve-animated-usenativedriver-is-not-supported-because-the-native#59593847
13+
jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
14+
15+
jest.mock("react-native-reanimated", () => {
16+
const Reanimated = require("react-native-reanimated/mock");
17+
18+
Reanimated.default.call = () => null;
19+
20+
Reanimated.useSharedValue = jest.fn;
21+
Reanimated.useAnimatedStyle = jest.fn;
22+
return Reanimated;
23+
});
24+
25+
jest.mock("react-native-gesture-handler", () =>
26+
jest.requireActual("react-native-gesture-handler/jestSetup")
27+
);
28+
29+
// jest.mock("@react-native-async-storage/async-storage", () =>
30+
// require("@react-native-async-storage/async-storage/jest/async-storage-mock")
31+
// );
32+
33+
jest.mock("@react-navigation/native", () => ({
34+
...jest.requireActual("@react-navigation/native"),
35+
useNavigation: () => ({
36+
navigate: jest.fn(),
37+
goBack: jest.fn(),
38+
}),
39+
useRoute: () => ({
40+
params: {
41+
publicToken: "testToken",
42+
},
43+
}),
44+
}));
45+
46+
// SOURCE: https://github.com/th3rdwave/react-native-safe-area-context#testing
47+
jest.mock("react-native-safe-area-context", () => mockSafeAreaContext);

jest.config.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
preset: "jest-expo",
3+
roots: ["<rootDir>"],
4+
testMatch: ["**/?(*.)+(spec|test).ts?(x)"],
5+
testPathIgnorePatterns: ["./node_modules/"],
6+
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
7+
moduleNameMapper: {
8+
"^@root(.*)$": "<rootDir>/src/$1",
9+
},
10+
transform: {
11+
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
12+
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest",
13+
},
14+
transformIgnorePatterns: [
15+
"node_modules/(?!(jest-)?react-native|@react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|sentry-expo|native-base)",
16+
],
17+
setupFilesAfterEnv: ["<rootDir>/__tests__/__mocks__/index.ts"],
18+
coverageReporters: ["json-summary", "text", "lcov"],
19+
collectCoverageFrom: [
20+
"**/*.{ts,tsx}",
21+
"!**/coverage/**",
22+
"!**/node_modules/**",
23+
"!**/babel.config.js",
24+
"!**/jest.setup.js",
25+
],
26+
};

0 commit comments

Comments
 (0)