Skip to content
This repository was archived by the owner on Dec 3, 2022. It is now read-only.

Commit f3b38ce

Browse files
committed
attempt to normalize the test setup according to other react-navigation projects (not yet working)
1 parent bb114e3 commit f3b38ce

File tree

6 files changed

+987
-548
lines changed

6 files changed

+987
-548
lines changed

jest-setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// nothing

jest.config.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
const { defaults: tsjPreset } = require('ts-jest/presets');
2-
31
module.exports = {
4-
...tsjPreset,
52
preset: 'react-native',
6-
transform: {
7-
...tsjPreset.transform,
8-
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
9-
},
10-
globals: {
11-
'ts-jest': {
12-
babelConfig: true,
13-
},
14-
},
15-
testPathIgnorePatterns: [
16-
"\\.snap$",
17-
"<rootDir>/node_modules/",
18-
"<rootDir>/dist/"
19-
],
3+
setupFiles: ['<rootDir>/jest-setup.js'],
4+
coveragePathIgnorePatterns: ['jest-setup.js'],
5+
modulePathIgnorePatterns: ['<rootDir>/example/'],
206
transformIgnorePatterns: [
21-
"<rootDir>/node_modules/(?!react-native)/"
7+
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element|react-navigation-deprecated-tab-navigator|@react-navigation/core|@react-navigation/native)',
228
],
23-
cacheDirectory: '.jest/cache',
9+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
10+
testRegex: '/__tests__/.*\\.(test|spec)\\.(js|tsx?)$',
11+
testEnvironment: 'node',
12+
transform: {
13+
'^.+\\.(js|ts|tsx)$': 'babel-jest',
14+
},
2415
};

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@
5454
"@types/jest": "^23.3.9",
5555
"@types/react": "^16.7.7",
5656
"@types/react-native": "^0.57.14",
57-
"@types/react-navigation": "^3.0.7",
5857
"@types/react-test-renderer": "^16.0.3",
58+
"babel-jest": "^24.7.1",
5959
"conventional-changelog-cli": "^2.0.5",
6060
"husky": "^0.14.3",
61-
"jest": "^23.6.0",
61+
"jest": "^24.7.1",
6262
"lint-staged": "^8.1.0",
6363
"prettier": "^1.8.2",
6464
"pretty-quick": "^1.8.0",
6565
"react": "^16.7.0-alpha.2",
6666
"react-native": "^0.57.7",
67+
"react-navigation": "^3.11.1",
6768
"react-test-renderer": "^16.7.0-alpha.2",
6869
"release-it": "^7.6.1",
69-
"ts-jest": "^23.10.5",
7070
"tslint": "^5.11.0",
7171
"tslint-config-airbnb": "^5.11.1",
7272
"tslint-config-prettier": "^1.16.0",

src/Hooks.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export function useNavigationEvents(handleEvt: NavigationEventCallback) {
3232
const navigation = useNavigation();
3333
useEffect(
3434
() => {
35-
const subsA = navigation.addListener('action', handleEvt);
35+
const subsA = navigation.addListener(
36+
'action' as any // TODO should we remove it? it's not in the published typedefs
37+
, handleEvt);
3638
const subsWF = navigation.addListener('willFocus', handleEvt);
3739
const subsDF = navigation.addListener('didFocus', handleEvt);
3840
const subsWB = navigation.addListener('willBlur', handleEvt);

src/__tests__/Hooks-test.tsx renamed to src/__tests__/Hooks.test.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { default as React, useState } from 'react';
1+
import * as React from 'react';
2+
import { useState } from 'react';
23
import * as renderer from 'react-test-renderer';
34
// @ts-ignore
45
import { createSwitchNavigator } from '@react-navigation/core';
@@ -114,7 +115,13 @@ describe('AppNavigator2 Stack', () => {
114115
navigationContainer = renderer.create(<App />);
115116
});
116117

117-
const eventTypes = ['willFocus', 'didFocus', 'willBlur', 'didBlur', 'action'];
118+
const eventTypes = [
119+
'willFocus',
120+
'didFocus',
121+
'willBlur',
122+
'didBlur',
123+
// 'action'
124+
];
118125

119126
it('usenNavigationState: Get current route name', () => {
120127
const children = navigationContainer.toJSON().children;

0 commit comments

Comments
 (0)