From 177ed0c51ea8c9f46287ccc44c4ae6936314c26f Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Wed, 6 Nov 2024 09:42:59 +0100 Subject: [PATCH 1/3] refactor: remove jest preset --- jest-preset/index.js | 10 ---------- jest-preset/restore-promise.js | 1 - jest-preset/save-promise.js | 1 - jest.config.js | 2 +- 4 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 jest-preset/index.js delete mode 100644 jest-preset/restore-promise.js delete mode 100644 jest-preset/save-promise.js diff --git a/jest-preset/index.js b/jest-preset/index.js deleted file mode 100644 index 40fe80597..000000000 --- a/jest-preset/index.js +++ /dev/null @@ -1,10 +0,0 @@ -const reactNativePreset = require('react-native/jest-preset'); - -module.exports = { - ...reactNativePreset, - // this is needed to make modern fake timers work - // because the react-native preset overrides global.Promise - setupFiles: [require.resolve('./save-promise.js')] - .concat(reactNativePreset.setupFiles) - .concat([require.resolve('./restore-promise.js')]), -}; diff --git a/jest-preset/restore-promise.js b/jest-preset/restore-promise.js deleted file mode 100644 index 196b35417..000000000 --- a/jest-preset/restore-promise.js +++ /dev/null @@ -1 +0,0 @@ -global.Promise = global.RNTL_ORIGINAL_PROMISE; diff --git a/jest-preset/save-promise.js b/jest-preset/save-promise.js deleted file mode 100644 index 30a5be234..000000000 --- a/jest-preset/save-promise.js +++ /dev/null @@ -1 +0,0 @@ -global.RNTL_ORIGINAL_PROMISE = Promise; diff --git a/jest.config.js b/jest.config.js index 5018adce5..459ad61aa 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - preset: './jest-preset', + preset: 'react-native', setupFilesAfterEnv: ['./jest-setup.ts'], testPathIgnorePatterns: ['build/', 'examples/', 'experiments-app/', 'timer-utils'], testTimeout: 60000, From ada58a23f8f3ff7b48b876117b95914661e24e6d Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Wed, 6 Nov 2024 09:44:16 +0100 Subject: [PATCH 2/3] chore: update docs --- website/docs/12.x/docs/api/misc/async.mdx | 16 +++++++++++++++- website/docs/13.x-alpha/docs/api/misc/async.mdx | 16 +--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/website/docs/12.x/docs/api/misc/async.mdx b/website/docs/12.x/docs/api/misc/async.mdx index 47b040629..8400db405 100644 --- a/website/docs/12.x/docs/api/misc/async.mdx +++ b/website/docs/12.x/docs/api/misc/async.mdx @@ -53,6 +53,12 @@ Avoiding side effects in `expectation` callback can be partially enforced with t 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. +### Using a React Native version < 0.71 with Jest fake timers + +:::caution +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). +::: + `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: ```tsx @@ -90,6 +96,10 @@ await waitFor(() => { }, 10000); ``` +:::info +In order to properly use `waitFor` you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0). +::: + :::note If you receive warnings related to `act()` function consult our [Undestanding Act](docs/advanced/understanding-act.md) function document. ::: @@ -119,6 +129,10 @@ This method expects that the element is initially present in the render tree and You can use any of `getBy`, `getAllBy`, `queryBy` and `queryAllBy` queries for `expectation` parameter. +:::info +In order to properly use `waitForElementToBeRemoved` you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0). +::: + :::note -If you receive warnings related to `act()` function consult our [Undestanding Act](docs/advanced/understanding-act.md) function document. +If you receive warnings related to `act()` function consult our [Understanding Act](docs/advanced/understanding-act.md) function document. ::: diff --git a/website/docs/13.x-alpha/docs/api/misc/async.mdx b/website/docs/13.x-alpha/docs/api/misc/async.mdx index 5ae3cf1c8..773999dac 100644 --- a/website/docs/13.x-alpha/docs/api/misc/async.mdx +++ b/website/docs/13.x-alpha/docs/api/misc/async.mdx @@ -53,12 +53,6 @@ Avoiding side effects in `expectation` callback can be partially enforced with t 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. -### Using a React Native version < 0.71 with Jest fake timers - -:::caution -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). -::: - `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: ```tsx @@ -96,10 +90,6 @@ await waitFor(() => { }, 10000); ``` -:::info -In order to properly use `waitFor` you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0). -::: - :::note If you receive warnings related to `act()` function consult our [Undestanding Act](docs/advanced/understanding-act.md) function document. ::: @@ -129,10 +119,6 @@ This method expects that the element is initially present in the render tree and You can use any of `getBy`, `getAllBy`, `queryBy` and `queryAllBy` queries for `expectation` parameter. -:::info -In order to properly use `waitForElementToBeRemoved` you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0). -::: - :::note -If you receive warnings related to `act()` function consult our [Undestanding Act](docs/advanced/understanding-act.md) function document. +If you receive warnings related to `act()` function consult our [Understanding Act](docs/advanced/understanding-act.md) function document. ::: From 63ad174739d7e55514c1addd6d3c249bf0cb58e1 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Wed, 6 Nov 2024 09:47:27 +0100 Subject: [PATCH 3/3] chore: remove files entry --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 8b4238adf..58ce5a07f 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ }, "files": [ "build/", - "jest-preset/", "matchers.js", "matchers.d.ts", "pure.js",