You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,8 @@
14
14
[![Chat][chat-badge]][chat]
15
15
[![Sponsored by Callstack][callstack-badge]][callstack]
16
16
17
+
> We renamed the `react-native-testing-library` npm package to `@testing-library/react-native`, officially joining the "Testing Library" family 🎉. Read the [migration guide](https://callstack.github.io/react-native-testing-library/docs/migration-v7).
18
+
17
19
## The problem
18
20
19
21
You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
Copy file name to clipboardExpand all lines: website/docs/MigrationV7.md
+15-11
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,17 @@ title: Migration to 7.0
4
4
---
5
5
6
6
:::caution
7
-
We renamed the `react-native-testing-library` npm package to `@testing-library/react-native`, joining the Testing Library family.
7
+
We renamed the `react-native-testing-library` npm package to `@testing-library/react-native`, officially joining the "Testing Library" family 🎉.
8
8
:::
9
9
10
10
As the version 7.0 involves merging two libraries together, there are two variants for migration guide, dependent on library you used previously:
11
11
12
-
-[guide for `react-native-testing-library` users](#guide-for-react-native-testing-library-users)
13
-
-[guide for `@testing-library/react-native` users](#guide-for-testing-libraryreact-native-users)
12
+
-[Guide for `react-native-testing-library` users](#guide-for-react-native-testing-library-users)
13
+
-[Guide for `@testing-library/react-native` users](#guide-for-testing-libraryreact-native-users)
14
14
15
15
# Guide for `react-native-testing-library` users
16
16
17
-
This guide describes steps necessary to migrate from React Native Testing Library `v2.x` to `v7.0`.
17
+
This guide describes steps necessary to migrate from React Native Testing Library `v2.x`or `v6.0`to `v7.0`.
18
18
19
19
## Renaming the library
20
20
@@ -46,21 +46,25 @@ Please replace all occurrences of these queries in your codebase.
46
46
47
47
## `fireEvent` support for disabled components
48
48
49
-
To improve compatibility with real React Native environment `fireEvent` now performs checks whether the component is disabled before firing an event on it. The checks internally uses `onStartShouldSetResponder` prop to establish should event fire, which should resemble the actual React Native runtime.
49
+
To improve compatibility with the real React Native environment `fireEvent` now performs checks whether the component is "disabled" before firing an event on it. It uses the Responder system to establish should the event fire, which resembles the actual React Native runtime closer than we used to.
50
50
51
51
If your code contained any workarounds for preventing events firing on disabled events, you should now be able to remove them.
52
52
53
53
# Guide for `@testing-library/react-native` users
54
54
55
55
This guide describes steps necessary to migrate from `@testing-library/react-native` from `v6.0` to `v7.0`. Although the name stays the same, this is a different library, sourced at [Callstack GitHub repository](https://github.com/callstack/react-native-testing-library). We made sure the upgrade path is as easy for you as possible.
56
56
57
-
## Changed helpers
57
+
## Renaming "wait" helpers
58
58
59
-
-`wait` and `waitForElement` are removed, rename these to `waitFor`
59
+
The`wait` and `waitForElement`helpers are replaced by `waitFor`. Please rename all occurrences of these in your codebase.
60
60
61
-
## Missing queries
61
+
## Changes to `ByTestId` queries
62
62
63
-
Our library doesn't implement `ByTitle` queries, which are targetting components with `title` prop, specifically `Button` and `RefreshControl`. If your tests only use `ByTitle` to target `Button` components, you can replace them with `ByText` queries, since React Native renders normal `Text` component under the hood.
63
+
The `ByTestId` queries don't accept RegExps. Please use strings instead. We're happy to accept PRs adding this functionality :).
64
+
65
+
## No `ByTitle` queries
66
+
67
+
Our library doesn't implement `ByTitle` queries, which are targetting components with `title` prop, specifically `Button` and `RefreshControl`. If your tests only use `ByTitle` to target `Button` components, you can replace them with `ByText` queries, since React Native renders `Text` under the hood.
64
68
65
69
If you need to query `RefreshControl` component and can't figure out other way around it, you can use e.g. `UNSAFE_getByProps({title})` query.
66
70
@@ -77,7 +81,7 @@ Use the official React Native preset for Jest:
77
81
}
78
82
```
79
83
80
-
We're told this should also speed up your tests startup on cold cache. Using official preset has another benefit. The library is compatible with any version of React Native without introducing breaking changes.
84
+
We're told this also speeds up your tests startup on cold cache. Using official preset has another benefit – the library is compatible with any version of React Native without introducing breaking changes.
81
85
82
86
## Cleanup is included by default
83
87
@@ -112,4 +116,4 @@ There are slight differences in how `fireEvent` works in both libraries:
1. There is no `NativeTestEvent` - second and rest arguments are used instead.
115
-
1. There are only 3 short-hand events: [`fireEvent.press`](`/docs/api/#fireeventpress-element-reacttestinstance--void`), [`fireEvent.changeText`](https://callstack.github.io/react-native-testing-library/docs/api/#fireeventchangetext-element-reacttestinstance-data-arrayany--void),[`fireEvent.scroll`](https://callstack.github.io/react-native-testing-library/docs/api/#fireeventchangetext-element-reacttestinstance-data-arrayany--void). For all other or custom events you can use the base signature.
119
+
1. There are only 3 short-hand events: [`fireEvent.press`](`/docs/api/#fireeventpress-element-reacttestinstance--void`), [`fireEvent.changeText`](https://callstack.github.io/react-native-testing-library/docs/api/#fireeventchangetext-element-reacttestinstance-data-arrayany--void) and[`fireEvent.scroll`](https://callstack.github.io/react-native-testing-library/docs/api/#fireeventchangetext-element-reacttestinstance-data-arrayany--void). For all other or custom events you can use the base signature.
0 commit comments