Skip to content

Commit 1ca2c55

Browse files
committed
fix: failing test
1 parent f87dcc9 commit 1ca2c55

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

__tests__/ListWithFetch.test.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React from 'react';
2-
import {cleanup, render, screen} from '@testing-library/react-native';
2+
import {
3+
cleanup,
4+
render,
5+
screen,
6+
waitForElementToBeRemoved,
7+
} from '@testing-library/react-native';
38
import ListWithFetch from '../src/components/ListWithFetch';
49
import {server} from '../src/test/mocks/server';
510
import {rest} from 'msw';
@@ -15,16 +20,19 @@ test('displays images from the server', async () => {
1520

1621
// Loader is initially visible
1722
expect(screen.getByLabelText(/loader/i)).toBeOnTheScreen();
18-
23+
await waitForElementToBeRemoved(() => screen.getByLabelText(/loader/i), {
24+
timeout: 1500,
25+
});
1926
// Verify that users are fetched and rendered
2027
expect(await screen.findAllByLabelText(/user-container/i)).toHaveLength(10);
2128

2229
// Verifying that the loader is no longer visible
2330
// There are 2 ways to verify that a component is not in the UI tree
24-
// 1. Use getBy* methods and expect them to throw an error with a corresponding message
25-
// 2. Use queryBy* methods and expect them to return null (See the next expect statement)
31+
// 1. Use waitForElementToBeRemoved to wait for the element to be removed from the DOM
32+
// 2. Use getBy* methods and expect them to throw an error with a corresponding message
33+
// 3. Use queryBy* methods and expect them to return null (See the next expect statement)
2634
expect(() => screen.getByLabelText(/loader/i)).toThrow(
27-
'Unable to find an element with accessibilityLabel: /loader/i',
35+
'Unable to find an element with accessibility label: /loader/i',
2836
);
2937

3038
// Verifying that there are no errors

0 commit comments

Comments
 (0)