Skip to content

v12 release #1314

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

Merged
merged 10 commits into from
Mar 15, 2023
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
6 changes: 0 additions & 6 deletions examples/basic/jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/* eslint-disable no-undef, import/no-extraneous-dependencies */
import { configure } from '@testing-library/react-native';

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

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

// Enable excluding hidden elements from the queries by default
configure({
defaultIncludeHiddenElements: false,
});
2 changes: 0 additions & 2 deletions examples/react-navigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ There are two types of recommeded tests:
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.
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.

> 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.

## Non-recommended tests

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/)**.
Expand Down
6 changes: 0 additions & 6 deletions examples/react-navigation/jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-undef, import/no-extraneous-dependencies */
import { configure } from '@testing-library/react-native';

// Import Jest Native matchers
import '@testing-library/jest-native/extend-expect';
Expand All @@ -10,8 +9,3 @@ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
// Setup Reanimated mocking for Drawer navigation
global.ReanimatedDataMock = { now: () => Date.now() };
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests();

// Enable excluding hidden elements from the queries by default
configure({
defaultIncludeHiddenElements: false,
});
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@testing-library/react-native",
"version": "11.5.4",
"version": "12.0.0-rc.2",
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand All @@ -10,6 +10,12 @@
},
"homepage": "https://callstack.github.io/react-native-testing-library",
"author": "Michał Pierzchała <thymikee@gmail.com>",
"contributors": [
"Maciej Jastrzębski <mdjastrzebski@gmail.com> (https://github.com/mdjastrzebski)",
"Augustin Le Fèvre <augustin.le-fevre@klarna.com> (https://github.com/AugustinLF)",
"Pierre Zimmermann <pierrez@nam.tech> (https://github.com/pierrezimmermannbam)",
"MattAgn <matthieua@bam.tech> (https://github.com/MattAgn)"
],
"license": "MIT",
"private": false,
"keywords": [
Expand Down
39 changes: 0 additions & 39 deletions src/__tests__/__snapshots__/render.breaking.test.tsx.snap

This file was deleted.

24 changes: 11 additions & 13 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
} from '../config';

test('getConfig() returns existing configuration', () => {
expect(getConfig().useBreakingChanges).toEqual(false);
expect(getConfig().asyncUtilTimeout).toEqual(1000);
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
});

test('configure() overrides existing config values', () => {
Expand All @@ -17,37 +16,36 @@ test('configure() overrides existing config values', () => {
expect(getConfig()).toEqual({
asyncUtilTimeout: 5000,
defaultDebugOptions: { message: 'debug message' },
defaultIncludeHiddenElements: true,
useBreakingChanges: false,
defaultIncludeHiddenElements: false,
});
});

test('resetToDefaults() resets config to defaults', () => {
configure({
asyncUtilTimeout: 5000,
defaultIncludeHiddenElements: false,
defaultIncludeHiddenElements: true,
});
expect(getConfig().asyncUtilTimeout).toEqual(5000);
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);

resetToDefaults();
expect(getConfig().asyncUtilTimeout).toEqual(1000);
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);
});

test('resetToDefaults() resets internal config to defaults', () => {
configureInternal({
useBreakingChanges: true,
hostComponentNames: { text: 'A', textInput: 'A' },
});
expect(getConfig().useBreakingChanges).toEqual(true);
expect(getConfig().hostComponentNames).toEqual({ text: 'A', textInput: 'A' });

resetToDefaults();
expect(getConfig().useBreakingChanges).toEqual(false);
expect(getConfig().hostComponentNames).toBe(undefined);
});

test('configure handles alias option defaultHidden', () => {
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);

configure({ defaultHidden: false });
expect(getConfig().defaultIncludeHiddenElements).toEqual(false);

configure({ defaultHidden: true });
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
});
Loading