Skip to content

Commit 24ac29a

Browse files
committed
chore: jest config updated
1 parent d70b37d commit 24ac29a

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

template/__tests__/App.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ test('examples of some things', async () => {
3636

3737
await waitFor(() => expect(queryByTestId('printed-username')).toBeTruthy());
3838

39-
expect(getByTestId('printed-username').props.children).toBe(famousProgrammerInHistory);
39+
// expect(getByTestId('printed-username').props.children).toBe(famousProgrammerInHistory);
40+
expect(getByTestId('printed-username')).toHaveTextContent(
41+
famousProgrammerInHistory,
42+
);
4043
expect(toJSON()).toMatchSnapshot();
4144
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`examples of some things 1`] = `
4+
<View>
5+
<TextInput
6+
allowFontScaling={true}
7+
onChangeText={[Function]}
8+
rejectResponderTermination={true}
9+
testID="input"
10+
underlineColorAndroid="transparent"
11+
value="Ada Lovelace"
12+
/>
13+
<View
14+
accessibilityRole="button"
15+
accessibilityState={Object {}}
16+
accessible={true}
17+
focusable={true}
18+
onClick={[Function]}
19+
onResponderGrant={[Function]}
20+
onResponderMove={[Function]}
21+
onResponderRelease={[Function]}
22+
onResponderTerminate={[Function]}
23+
onResponderTerminationRequest={[Function]}
24+
onStartShouldSetResponder={[Function]}
25+
style={
26+
Object {
27+
"opacity": 1,
28+
}
29+
}
30+
>
31+
<View
32+
style={
33+
Array [
34+
Object {},
35+
]
36+
}
37+
>
38+
<Text
39+
style={
40+
Array [
41+
Object {
42+
"color": "#007AFF",
43+
"fontSize": 18,
44+
"margin": 8,
45+
"textAlign": "center",
46+
},
47+
]
48+
}
49+
>
50+
Print Username
51+
</Text>
52+
</View>
53+
</View>
54+
<Text
55+
testID="printed-username"
56+
>
57+
Ada Lovelace
58+
</Text>
59+
</View>
60+
`;

template/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
preset: 'react-native',
33
testEnvironment: 'node',
4+
setupFilesAfterEnv: ['./jest.setup'],
45
};

template/jest.setup.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import '@testing-library/jest-native/extend-expect';
2+
23
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';
34
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
45

56
import { jest } from '@jest/globals';
6-
import { server } from './src/test/mocks/server';
77

88
jest.mock('@react-native-community/netinfo', () => mockRNCNetInfo);
99
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
1010

11-
jest.mock('@sentry/react-native', () => ({
11+
jest.doMock('@sentry/react-native', () => ({
1212
init: jest.fn(),
1313
}));
1414

15-
jest.mock('react-native-reanimated', () => {
15+
jest.doMock('react-native-reanimated', () => {
1616
// eslint-disable-next-line @typescript-eslint/no-var-requires
1717
const Reanimated = require('react-native-reanimated/mock');
1818

@@ -24,7 +24,7 @@ jest.mock('react-native-reanimated', () => {
2424
});
2525

2626
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
27-
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
27+
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
2828

2929
jest.mock('nanoid/non-secure', () => ({
3030
nanoid: () => 'routeUniqId',
@@ -42,7 +42,6 @@ jest.mock('react-native/Libraries/Components/Switch/Switch', () => {
4242
return mockComponent('react-native/Libraries/Components/Switch/Switch');
4343
});
4444

45-
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
4645
jest.mock('react-native-gesture-handler', () => {
4746
// eslint-disable-next-line @typescript-eslint/no-var-requires
4847
const View = require('react-native/Libraries/Components/View/View');
@@ -78,9 +77,6 @@ jest.mock('react-native-gesture-handler', () => {
7877
};
7978
});
8079

81-
//establish api mocking before all tests
82-
beforeAll(() => server.listen());
83-
8480
beforeEach(() => {
8581
global.fetch = jest.fn((...args) => {
8682
console.warn('global.fetch needs to be mocked in tests', ...args);
@@ -89,11 +85,9 @@ beforeEach(() => {
8985
});
9086

9187
//clean up after the tests are finished
92-
afterAll(() => server.close());
9388

9489
afterEach(() => {
9590
global.fetch.mockRestore();
9691
//reset any requests handlers that we may add during the tests,
9792
//so they don't affect other tests.
98-
server.resetHandlers();
9993
});

0 commit comments

Comments
 (0)