-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: find by timeout with detached screen (#1576)
* fix: improve error findBy* error message when screen is not beign attached. * fix: detect detached screen and display proper error message. * chore: improve error message * chore: update link * chore: update snapshots
- Loading branch information
1 parent
9b252f8
commit b2a29b1
Showing
3 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
import { View } from 'react-native'; | ||
import { render, screen } from '../..'; | ||
import { clearRenderResult } from '../../screen'; | ||
|
||
test('findByTestId detects screen being detached', async () => { | ||
render(<View />); | ||
|
||
const promise = screen.findByTestId('not-exists', {}, { timeout: 50 }); | ||
|
||
// Detach screen | ||
clearRenderResult(); | ||
|
||
await expect(promise).rejects.toThrowErrorMatchingInlineSnapshot(` | ||
"Unable to find an element with testID: not-exists | ||
Screen is no longer attached. Check your test for "findBy*" or "waitFor" calls that have not been awaited. | ||
We recommend enabling "eslint-plugin-testing-library" to catch these issues at build time: | ||
https://callstack.github.io/react-native-testing-library/docs/getting-started#eslint-plugin" | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters