Skip to content

Commit

Permalink
chore: configure jest to use with ts (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian authored Oct 21, 2024
1 parent 4457490 commit a580957
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
11 changes: 8 additions & 3 deletions setup-jest.js → jest-setup.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = {};
keys.forEach((key) => (obj[key] = key));
return obj;
}
Expand Down Expand Up @@ -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 }),
Expand Down
11 changes: 6 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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}"],
};
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a580957

Please sign in to comment.