Skip to content

Commit 4256d0c

Browse files
mdjastrzebskithymikeepierrezimmermannbam
authored
v12 release (#1314)
Co-authored-by: Michał Pierzchała <thymikee@gmail.com> Co-authored-by: Pierre Zimmermann <64224599+pierrezimmermannbam@users.noreply.github.com>
1 parent c4d36e4 commit 4256d0c

36 files changed

+280
-1969
lines changed

examples/basic/jest-setup.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* eslint-disable no-undef, import/no-extraneous-dependencies */
2-
import { configure } from '@testing-library/react-native';
32

43
// Import Jest Native matchers
54
import '@testing-library/jest-native/extend-expect';
65

76
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
87
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
9-
10-
// Enable excluding hidden elements from the queries by default
11-
configure({
12-
defaultIncludeHiddenElements: false,
13-
});

examples/react-navigation/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ There are two types of recommeded tests:
88
1. Tests operating on navigator level - these use `renderNavigator` helper to render a navigator component used in the app. It is useful when you want to test a scenario that includes multiple screens.
99
2. Tests operating on single screen level - these use regular `render` helper but require refactoring screen components into `Screen` and `ScreenContent` components. Where `Screen` receives React Navigation props and/or uses hooks like `useNavigation` while `ScreenContent` does not have a direct relation to React Navigation API but gets props from `Screen` and calls relevant callbacks to trigger navigation.
1010

11-
> Note that this example applies `includeHiddenElements: false` by default, so all queries will ignore elements on the hidden screens, e.g. inactive tabs or screens present in stack navigators. This option is enabled in `jest-setup.js` file, using `defaultIncludeHiddenElements: false` option to `configure` function.
12-
1311
## Non-recommended tests
1412

1513
There also exists another popular type of screen level tests, where users mock React Navigation objects like `navigation`, `route` and/or hooks like `useNavigation`, etc. We don't recommend this way of testing. **Mocking internal parts of the libraries is effectively testing implementation details, which goes against the Testing Library's [Guiding Principles](https://testing-library.com/docs/guiding-principles/)**.
-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-undef, import/no-extraneous-dependencies */
2-
import { configure } from '@testing-library/react-native';
32

43
// Import Jest Native matchers
54
import '@testing-library/jest-native/extend-expect';
@@ -10,8 +9,3 @@ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
109
// Setup Reanimated mocking for Drawer navigation
1110
global.ReanimatedDataMock = { now: () => Date.now() };
1211
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests();
13-
14-
// Enable excluding hidden elements from the queries by default
15-
configure({
16-
defaultIncludeHiddenElements: false,
17-
});

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@testing-library/react-native",
3-
"version": "11.5.4",
3+
"version": "12.0.0-rc.2",
44
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",
@@ -10,6 +10,12 @@
1010
},
1111
"homepage": "https://callstack.github.io/react-native-testing-library",
1212
"author": "Michał Pierzchała <thymikee@gmail.com>",
13+
"contributors": [
14+
"Maciej Jastrzębski <mdjastrzebski@gmail.com> (https://github.com/mdjastrzebski)",
15+
"Augustin Le Fèvre <augustin.le-fevre@klarna.com> (https://github.com/AugustinLF)",
16+
"Pierre Zimmermann <pierrez@nam.tech> (https://github.com/pierrezimmermannbam)",
17+
"MattAgn <matthieua@bam.tech> (https://github.com/MattAgn)"
18+
],
1319
"license": "MIT",
1420
"private": false,
1521
"keywords": [

src/__tests__/__snapshots__/render.breaking.test.tsx.snap

-39
This file was deleted.

src/__tests__/config.test.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {
66
} from '../config';
77

88
test('getConfig() returns existing configuration', () => {
9-
expect(getConfig().useBreakingChanges).toEqual(false);
109
expect(getConfig().asyncUtilTimeout).toEqual(1000);
11-
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
10+
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
1211
});
1312

1413
test('configure() overrides existing config values', () => {
@@ -17,37 +16,36 @@ test('configure() overrides existing config values', () => {
1716
expect(getConfig()).toEqual({
1817
asyncUtilTimeout: 5000,
1918
defaultDebugOptions: { message: 'debug message' },
20-
defaultIncludeHiddenElements: true,
21-
useBreakingChanges: false,
19+
defaultIncludeHiddenElements: false,
2220
});
2321
});
2422

2523
test('resetToDefaults() resets config to defaults', () => {
2624
configure({
2725
asyncUtilTimeout: 5000,
28-
defaultIncludeHiddenElements: false,
26+
defaultIncludeHiddenElements: true,
2927
});
3028
expect(getConfig().asyncUtilTimeout).toEqual(5000);
31-
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
29+
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
3230

3331
resetToDefaults();
3432
expect(getConfig().asyncUtilTimeout).toEqual(1000);
35-
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
33+
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
3634
});
3735

3836
test('resetToDefaults() resets internal config to defaults', () => {
3937
configureInternal({
40-
useBreakingChanges: true,
38+
hostComponentNames: { text: 'A', textInput: 'A' },
4139
});
42-
expect(getConfig().useBreakingChanges).toEqual(true);
40+
expect(getConfig().hostComponentNames).toEqual({ text: 'A', textInput: 'A' });
4341

4442
resetToDefaults();
45-
expect(getConfig().useBreakingChanges).toEqual(false);
43+
expect(getConfig().hostComponentNames).toBe(undefined);
4644
});
4745

4846
test('configure handles alias option defaultHidden', () => {
49-
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
50-
51-
configure({ defaultHidden: false });
5247
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
48+
49+
configure({ defaultHidden: true });
50+
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
5351
});

0 commit comments

Comments
 (0)