Give up trying to add unit tests

Running tests gives the following error:
TypeError: _reactNative.BackHandler.addEventListener is not a function
This commit is contained in:
Brandon Presley 2022-10-29 17:14:27 +13:00
parent 4aa62dace8
commit cc97c760bb
6 changed files with 61 additions and 9757 deletions

14
__tests__/App-test.tsx Normal file
View File

@ -0,0 +1,14 @@
/**
* @format
*/
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
renderer.create(<App />);
});

11
jest.config.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.(js|jsx)$': 'babel-jest',
},
transformIgnorePatterns: [
'node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)',
],
setupFiles: ['./jestSetup.ts'],
};

21
jestSetup.ts Normal file
View File

@ -0,0 +1,21 @@
import {NativeModules as RNNativeModules} from 'react-native';
RNNativeModules.UIManager = RNNativeModules.UIManager || {};
RNNativeModules.UIManager.RCTView = RNNativeModules.UIManager.RCTView || {};
RNNativeModules.RNGestureHandlerModule =
RNNativeModules.RNGestureHandlerModule || {
State: {BEGAN: 'BEGAN', FAILED: 'FAILED', ACTIVE: 'ACTIVE', END: 'END'},
attachGestureHandler: jest.fn(),
createGestureHandler: jest.fn(),
dropGestureHandler: jest.fn(),
updateGestureHandler: jest.fn(),
};
RNNativeModules.PlatformConstants = RNNativeModules.PlatformConstants || {
forceTouchAvailable: false,
};
RNNativeModules.RNViewShot = RNNativeModules.RNViewShot || {
captureScreen: jest.fn(),
};
jest.mock('react-native-file-access', () => jest.fn());
jest.mock('react-native-share', () => jest.fn());

View File

@ -17,11 +17,17 @@
"@react-navigation/drawer": "^6.5.0",
"@react-navigation/native": "^6.0.13",
"@react-navigation/stack": "^6.3.0",
"@testing-library/jest-native": "^5.1.2",
"@testing-library/react-native": "^11.3.0",
"@types/d3-shape": "^3.1.0",
"@types/jest": "^29.2.0",
"@types/react-native-sqlite-storage": "^5.0.2",
"@types/react-native-svg-charts": "^5.0.12",
"@types/react-native-vector-icons": "^6.4.12",
"babel-jest": "^29.2.2",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint-plugin-flowtype": "^8.0.3",
"jest": "^29.2.2",
"react": "^18.2.0",
"react-native": "^0.70.4",
"react-native-document-picker": "^8.1.2",
@ -38,7 +44,8 @@
"react-native-svg": "^13.4.0",
"react-native-svg-charts": "^5.4.0",
"react-native-vector-icons": "^9.2.0",
"react-native-view-shot": "^3.4.0"
"react-native-view-shot": "^3.4.0",
"react-test-renderer": "^18.2.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",

View File

@ -5,7 +5,7 @@
"jsx": "react-native",
"module": "CommonJS",
"moduleResolution": "node",
"types": ["react-native"],
"types": ["react-native", "jest"],
"resolveJsonModule": true,
"allowJs": true,
"noEmit": true,
@ -16,5 +16,10 @@
"strict": true,
"skipLibCheck": true
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js"]
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}

9754
yarn.lock

File diff suppressed because it is too large Load Diff