diff --git a/setup-jest.js b/jest-setup.ts similarity index 88% rename from setup-jest.js rename to jest-setup.ts index 012cc97e6..646c151ff 100644 --- a/setup-jest.js +++ b/jest-setup.ts @@ -1,7 +1,12 @@ +/* eslint-disable no-undef, import/no-extraneous-dependencies */ +import "@testing-library/react-native/extend-expect"; import { NativeModules } from "react-native"; -function keyMirror(keys) { - const obj = {}; +// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing +jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper"); + +function keyMirror(keys: string[]) { + const obj: Record = {}; keys.forEach((key) => (obj[key] = key)); return obj; } @@ -77,7 +82,7 @@ NativeModules.MLNModule = { }; NativeModules.MLNOfflineModule = { - createPack: (packOptions) => { + createPack: (packOptions: any) => { return Promise.resolve({ bounds: packOptions.bounds, metadata: JSON.stringify({ name: packOptions.name }), diff --git a/jest.config.js b/jest.config.js index 0b2a61fca..b735c7cba 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,8 @@ -/** @type {import('@jest/types').Config.InitialOptions} */ module.exports = { - preset: "react-native", - collectCoverageFrom: ["javascript/**/*.js"], - setupFiles: ["./setup-jest.js", "./__tests__/__mocks__/react-native.mock.js"], - modulePathIgnorePatterns: ["example", "__tests__/__mocks__", "fixtures"], + preset: "@testing-library/react-native", + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"], + setupFilesAfterEnv: ["./jest-setup.ts"], + setupFiles: ["./__tests__/__mocks__/react-native.mock.js"], + modulePathIgnorePatterns: ["__tests__/__mocks__", "fixtures"], + collectCoverageFrom: ["javascript/**/*.{ts,tsx,js,jsx}"], }; diff --git a/tsconfig.json b/tsconfig.json index 9cf78eaed..71f06c61d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,12 +10,12 @@ "isolatedModules": true, "skipLibCheck": true, "strict": true, - "types": ["node", "react-native", "geojson"], + "types": ["node", "react-native", "geojson", "jest"], "moduleResolution": "node", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "noUnusedLocals": true, - "noImplicitReturns": true, + "noImplicitReturns": true }, "include": [ "javascript/**/*", "index.ts"