Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest setup #138

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ESLint/Prettier/Airbnb style check
name: Client code check

on:
push:
Expand All @@ -22,3 +22,16 @@ jobs:
run: yarn
- name: Run ESLint
run: npx eslint src
jest_tests:
name: Jest testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
yarn
- name: Run test
run: |
yarn test
working-directory: src

4 changes: 4 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const appConfig = require("./src/app.json");

// Used by jest-expo
module.exports = appConfig;
29 changes: 29 additions & 0 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import renderer, { act } from 'react-test-renderer';
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';

import App from './App';

jest.mock(
'./env',
() => ({ CLIENT_ID: 'client_id', CLIENT_SECRET: 'client_secret' }),
{ virtual: true }
);
jest.mock('./app/hooks/useCachedResources', () => jest.fn(() => true));
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
jest.mock('@react-navigation/native/lib/commonjs/useLinking.native', () => ({
default: () => ({ getInitialState: { then: jest.fn() } }),
__esModule: true,
}));

describe('<App />', () => {
it('has 1 child', async () => {
const tree = renderer
.create(<App />)
.toJSON() as renderer.ReactTestRendererJSON;

await act(async () =>
expect([1, undefined]).toContain(tree.children?.length)
);
});
});
10 changes: 0 additions & 10 deletions src/app/components/__tests__/StyledText.test.jsx

This file was deleted.

20 changes: 15 additions & 5 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest --watchAll"
},
"jest": {
"preset": "jest-expo"
"test": "jest"
},
"dependencies": {
"@babel/runtime": "^7.17.2",
Expand Down Expand Up @@ -47,8 +44,10 @@
},
"devDependencies": {
"@babel/core": "^7.17.3",
"@types/jest": "^27.4.1",
"@types/react": "~17.0.39",
"@types/react-native": "~0.66.15",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
Expand All @@ -60,11 +59,22 @@
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-react-native": "^4.0.0",
"expo-updates": "^0.11.6",
"jest": "26.6.3",
"jest-expo": "~44.0.1",
"prettier": "^2.4.1",
"prettylint": "^1.0.0",
"react-test-renderer": "^17.0.2",
"react-test-renderer": "17.0.2",
"typescript": "^4.5.2"
},
"jest": {
"preset": "jest-expo",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
},
"private": true
}
3 changes: 1 addition & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"typeRoots": ["./ts-declarations", "node_modules/@types", "app/types"]
"strict": true
}
}
Loading