Add jest for unit tests

This commit is contained in:
Kat Huang 2024-01-06 18:42:41 -07:00
parent c292289f29
commit d68561b372
4 changed files with 1290 additions and 44 deletions

View File

@ -21,3 +21,5 @@ jobs:
run: nix develop --impure --command bash -c 'export HOME=$PWD; yarn run lint' run: nix develop --impure --command bash -c 'export HOME=$PWD; yarn run lint'
- name: typecheck - name: typecheck
run: nix develop --impure --command bash -c 'export HOME=$PWD; yarn tsc --noEmit' run: nix develop --impure --command bash -c 'export HOME=$PWD; yarn tsc --noEmit'
- name: test
run: nix develop --impure --command bash -c 'export HOME=$PWD; yarn run test'

View File

@ -10,8 +10,14 @@
"lint": "eslint . --ext .js,.ts,.tsx", "lint": "eslint . --ext .js,.ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix", "lint:fix": "eslint . --ext .ts,.tsx --fix",
"start:dev": "ENVFILE=.env.development react-native start", "start:dev": "ENVFILE=.env.development react-native start",
"start:prod": "ENVFILE=.env.production react-native start" "start:prod": "ENVFILE=.env.production react-native start",
"test": "jest"
}, },
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
]},
"dependencies": { "dependencies": {
"@types/react": "~18.2.14", "@types/react": "~18.2.14",
"@typescript-eslint/eslint-plugin": "^6.17.0", "@typescript-eslint/eslint-plugin": "^6.17.0",
@ -22,13 +28,16 @@
"eslint-plugin-react-native": "^4.1.0", "eslint-plugin-react-native": "^4.1.0",
"expo": "~49.0.15", "expo": "~49.0.15",
"expo-status-bar": "~1.6.0", "expo-status-bar": "~1.6.0",
"jest": "^29.2.1",
"jest-expo": "~49.0.0",
"react": "18.2.0", "react": "18.2.0",
"react-native": "0.72.6", "react-native": "0.72.6",
"react-native-dotenv": "^3.4.9", "react-native-dotenv": "^3.4.9",
"typescript": "^5.3.3" "typescript": "^5.3.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.0" "@babel/core": "^7.20.0",
"@types/jest": "^29.5.11"
}, },
"private": true "private": true
} }

12
tests/App.test.js Normal file
View File

@ -0,0 +1,12 @@
import React from "react";
import renderer from "react-test-renderer";
import App from "./App";
describe("<App />", () => {
it("has 1 child", () => {
const tree = renderer.create(<App />).toJSON();
expect(tree.children.length).toBe(1);
});
});

1307
yarn.lock

File diff suppressed because it is too large Load Diff