diff --git a/README.md b/README.md index aaef02bf8..893836e1d 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,24 @@ Then automatically add it to your jest tests by using `setupFilesAfterEnv` optio } ``` +### Custom Jest Preset + +> **important** if you use "modern" Fake Timers + +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. + +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. + +Here's how you apply a custom preset in your Jest config: + +```json +{ + "preset": "@testing-library/react-native" +} +``` + +If this doesn't work for you, please fall back to using "legacy" fake timers. + ### Flow Note for [Flow](https://flow.org) users – you'll also need to install typings for `react-test-renderer`: diff --git a/jest/preset.js b/jest-preset/index.js similarity index 100% rename from jest/preset.js rename to jest-preset/index.js diff --git a/jest/restore-promise.js b/jest-preset/restore-promise.js similarity index 100% rename from jest/restore-promise.js rename to jest-preset/restore-promise.js diff --git a/jest/save-promise.js b/jest-preset/save-promise.js similarity index 100% rename from jest/save-promise.js rename to jest-preset/save-promise.js diff --git a/package.json b/package.json index 3b9d2dae7..277a6ad4c 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ ], "files": [ "build/", + "jest-preset/", "typings/index.d.ts", "pure.js", "dont-cleanup-after-each.js" @@ -70,7 +71,7 @@ "build": "rm -rf build; babel src --out-dir build --ignore 'src/__tests__/*'" }, "jest": { - "preset": "../jest/preset.js", + "preset": "../jest-preset", "moduleFileExtensions": [ "js", "json"