Skip to content

Commit 43e02e4

Browse files
pierrezimmermannbampierrezimmermannmdjastrzebski
authored
docs: update docs on custom jest preset (#1316)
* docs: update docs on custom jest preset * docs: flip conditions on modern timers and react native version * Update README.md Co-authored-by: Maciej Jastrzebski <[email protected]> * Update title in readme for custom jest preset Co-authored-by: Maciej Jastrzebski <[email protected]> --------- Co-authored-by: pierrezimmermann <[email protected]> Co-authored-by: Maciej Jastrzebski <[email protected]>
1 parent 3739c89 commit 43e02e4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Then automatically add it to your jest tests by using `setupFilesAfterEnv` optio
7272
}
7373
```
7474

75-
### Custom Jest Preset
75+
### Custom Jest Preset (React Native before 0.71)
7676

77-
> **important** if you use "modern" Fake Timers
77+
We generally advise to use the "react-native" preset when testing with this library.
7878

79-
We generally advise to use the "react-native" preset when testing with this library. However, if you use ["modern" Fake Timers](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers) (default since Jest 27), you'll need to apply our custom Jest preset or awaiting promises, like `waitFor`, will timeout.
79+
However, if you use React Native version earlier than 0.71 with [modern Jest fake timers](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers) (default since Jest 27), you'll need to apply this custom Jest preset or otherwise awaiting promises, like using `waitFor` or `findBy*`, queries will fail with timeout.
8080

8181
This is a [known issue](https://github.com/facebook/react-native/issues/29303). It happens because React Native's Jest preset overrides native Promise. Our preset restores it to defaults, which is not a problem in most apps out there.
8282

website/docs/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,10 @@ Avoiding side effects in `expectation` callback can be partially enforced with t
579579

580580
It is also recommended to have a [single assertion per each `waitFor`](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#having-multiple-assertions-in-a-single-waitfor-callback) for more consistency and faster failing tests. If you want to make several assertions, then they should be in seperate `waitFor` calls. In many cases you won't actually need to wrap the second assertion in `waitFor` since the first one will do the waiting required for asynchronous change to happen.
581581

582-
### Using Jest fake timers
582+
### Using a React Native version < 0.71 with Jest fake timers
583583

584584
:::caution
585-
When using modern fake timers (the default for `Jest` >= 27), `waitFor` won't work (it will always timeout even if `expectation()` doesn't throw) unless you use the custom [@testing-library/react-native preset](https://github.com/callstack/react-native-testing-library#custom-jest-preset).
585+
When using a version of React Native < 0.71 and modern fake timers (the default for `Jest` >= 27), `waitFor` won't work (it will always timeout even if `expectation()` doesn't throw) unless you use the custom [@testing-library/react-native preset](https://github.com/callstack/react-native-testing-library#custom-jest-preset).
586586
:::
587587

588588
`waitFor` checks whether Jest fake timers are enabled and adapts its behavior in such case. The following snippet is a simplified version of how it behaves when fake timers are enabled:

0 commit comments

Comments
 (0)