Skip to content

Commit 62ccd08

Browse files
authored
feat: expose custom Jest preset restoring global Promise (#695)
* feat: expose custom Jest preset restoring global Promise * typo
1 parent 2ccec3c commit 62ccd08

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ Then automatically add it to your jest tests by using `setupFilesAfterEnv` optio
7373
}
7474
```
7575

76+
### Custom Jest Preset
77+
78+
> **important** if you use "modern" Fake Timers
79+
80+
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.
81+
82+
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.
83+
84+
Here's how you apply a custom preset in your Jest config:
85+
86+
```json
87+
{
88+
"preset": "@testing-library/react-native"
89+
}
90+
```
91+
92+
If this doesn't work for you, please fall back to using "legacy" fake timers.
93+
7694
### Flow
7795

7896
Note for [Flow](https://flow.org) users – you'll also need to install typings for `react-test-renderer`:
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
],
2121
"files": [
2222
"build/",
23+
"jest-preset/",
2324
"typings/index.d.ts",
2425
"pure.js",
2526
"dont-cleanup-after-each.js"
@@ -70,7 +71,7 @@
7071
"build": "rm -rf build; babel src --out-dir build --ignore 'src/__tests__/*'"
7172
},
7273
"jest": {
73-
"preset": "../jest/preset.js",
74+
"preset": "../jest-preset",
7475
"moduleFileExtensions": [
7576
"js",
7677
"json"

0 commit comments

Comments
 (0)