Skip to content

Commit a580957

Browse files
authored
chore: configure jest to use with ts (#470)
1 parent 4457490 commit a580957

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

setup-jest.js renamed to jest-setup.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
/* eslint-disable no-undef, import/no-extraneous-dependencies */
2+
import "@testing-library/react-native/extend-expect";
13
import { NativeModules } from "react-native";
24

3-
function keyMirror(keys) {
4-
const obj = {};
5+
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
6+
jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
7+
8+
function keyMirror(keys: string[]) {
9+
const obj: Record<string, string> = {};
510
keys.forEach((key) => (obj[key] = key));
611
return obj;
712
}
@@ -77,7 +82,7 @@ NativeModules.MLNModule = {
7782
};
7883

7984
NativeModules.MLNOfflineModule = {
80-
createPack: (packOptions) => {
85+
createPack: (packOptions: any) => {
8186
return Promise.resolve({
8287
bounds: packOptions.bounds,
8388
metadata: JSON.stringify({ name: packOptions.name }),

jest.config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/** @type {import('@jest/types').Config.InitialOptions} */
21
module.exports = {
3-
preset: "react-native",
4-
collectCoverageFrom: ["javascript/**/*.js"],
5-
setupFiles: ["./setup-jest.js", "./__tests__/__mocks__/react-native.mock.js"],
6-
modulePathIgnorePatterns: ["example", "__tests__/__mocks__", "fixtures"],
2+
preset: "@testing-library/react-native",
3+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
4+
setupFilesAfterEnv: ["./jest-setup.ts"],
5+
setupFiles: ["./__tests__/__mocks__/react-native.mock.js"],
6+
modulePathIgnorePatterns: ["__tests__/__mocks__", "fixtures"],
7+
collectCoverageFrom: ["javascript/**/*.{ts,tsx,js,jsx}"],
78
};

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"isolatedModules": true,
1111
"skipLibCheck": true,
1212
"strict": true,
13-
"types": ["node", "react-native", "geojson"],
13+
"types": ["node", "react-native", "geojson", "jest"],
1414
"moduleResolution": "node",
1515
"allowSyntheticDefaultImports": true,
1616
"esModuleInterop": true,
1717
"noUnusedLocals": true,
18-
"noImplicitReturns": true,
18+
"noImplicitReturns": true
1919
},
2020
"include": [
2121
"javascript/**/*", "index.ts"

0 commit comments

Comments
 (0)