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
This is in contrast to the `toBeOnTheScreen` matcher, which checks if the element is rendered in the component tree. This matcher is not recommended when writing tests involving navigation.
150
150
151
-
By default, the queries from React Native Testing Library (e.g. `getByRole`, `getByText`, `getByLabelText` etc.) [only return visible elements](https://callstack.github.io/react-native-testing-library/docs/api/queries#includehiddenelements-option). So you don't need to do anything special. However, if you're using a different library for your tests, you'll need to account for this behavior.
151
+
By default, the queries from React Native Testing Library (e.g. `getByRole`, `getByText`, `getByLabelText` etc.) [only return visible elements](https://oss.callstack.com/react-native-testing-library/docs/api/queries#includehiddenelements-option). So you don't need to do anything special. However, if you're using a different library for your tests, you'll need to account for this behavior.
152
152
153
153
## Example tests
154
154
155
-
We recommend using [React Native Testing Library](https://callstack.github.io/react-native-testing-library/) to write your tests.
155
+
We recommend using [React Native Testing Library](https://oss.callstack.com/react-native-testing-library/) to write your tests.
156
156
157
157
In this guide, we will go through some example scenarios and show you how to write tests for them using Jest and React Native Testing Library:
158
158
@@ -246,13 +246,13 @@ test('navigates to settings by tab bar button press', async () => {
246
246
247
247
constNavigation=createStaticNavigation(MyTabs);
248
248
249
-
render(<Navigation />);
249
+
awaitrender(<Navigation />);
250
250
251
251
constbutton=screen.getByRole('button', { name:'Settings, tab, 2 of 2' });
@@ -294,8 +296,8 @@ test('navigates to settings by tab bar button press', async () => {
294
296
295
297
In the above test, we:
296
298
297
-
- Render the `MyTabs` navigator within a [NavigationContainer](navigation-container.md)in our test.
298
-
- Get the tab bar button using the `getByLabelText` query that matches its accessibility label.
299
+
- Render the `MyTabs` navigator using [`createStaticNavigation`](static-configuration.md#createstaticnavigation) for static configuration or a [NavigationContainer](navigation-container.md)for dynamic configuration.
300
+
- Get the tab bar button using the `getByRole` query that matches its role and accessible name.
299
301
- Press the button using `userEvent.press(button)` to simulate a user interaction.
300
302
- Run all timers using `jest.runAllTimers()` to skip animations (e.g. animations in the `Pressable` for the button).
301
303
- Assert that the `Settings screen` is visible after the navigation.
@@ -422,11 +424,11 @@ test('shows surprise text after navigating to surprise screen', async () => {
@@ -466,8 +468,8 @@ test('shows surprise text after navigating to surprise screen', async () => {
466
468
467
469
In the above test, we:
468
470
469
-
- Render the `MyStack` navigator within a [NavigationContainer](navigation-container.md)in our test.
470
-
- Get the button using the `getByLabelText` query that matches its title.
471
+
- Render the `MyStack` navigator using [`createStaticNavigation`](static-configuration.md#createstaticnavigation) for static configuration or a [NavigationContainer](navigation-container.md)for dynamic configuration.
472
+
- Get the button using the `getByRole` query that matches its role and accessible name.
471
473
- Press the button using `userEvent.press(button)` to simulate a user interaction.
472
474
- Run all timers using `jest.runAllTimers()` to skip animations (e.g. navigation animation between screens).
473
475
- Assert that the `Surprise!` text is visible after the transition to the Surprise screen is complete.
@@ -696,10 +698,14 @@ test('loads data on Pokemon info screen after focus', async () => {
696
698
697
699
constNavigation=createStaticNavigation(MyTabs);
698
700
699
-
render(<Navigation />);
701
+
awaitrender(<Navigation />);
700
702
701
-
consthomeTabButton=screen.getByLabelText('Home, tab, 1 of 2');
702
-
constpokemonTabButton=screen.getByLabelText('Pokemon, tab, 2 of 2');
0 commit comments