Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix erroneous react-dom usage in native tests (#37921)
* Reinstate react-platform.native.js file This file was removed in the following commit, as it was no longer strictly necessary. b7b62d2#diff-f02069349f238fb47a268bb7fcc03c9768331db18ead0e28d8ecad7bbc05037c However, the removal led to Jest loading the DOM-specific version of the file when mocking Gutenberg modules that depended upon `react-platform.js`. Jest would seemingly load `react-dom` when attempting to auto-mock a module, e.g. `jest.mock( '@wordpress/data/src/components/use-select' );`. The loading of `react-dom` resulted in the following error: ``` TypeError: Cannot use 'in' operator to search for 'WebkitAnimation' in undefined at getVendorPrefixedEventName (node_modules/react-dom/cjs/react-dom.development.js:5011:58) at node_modules/react-dom/cjs/react-dom.development.js:5019:21 at Object.<anonymous> (node_modules/react-dom/cjs/react-dom.development.js:26261:5) at Object.<anonymous> (node_modules/react-dom/index.js:37:20) ``` Reinstating `react-platform.native.js` addresses this issue by ensuring that Jest does not encounter an import of `react-dom`. * Fix false-positive ReactNativeEditor test This test failed when run in isolation. It would appear it was dependent upon the `jest.mock('../setup')` found in sibling tests. After defining a mock for this specific test, it was discovered that the assertion did not await the asynchronous query found within the test. The assertion resulted in a false-positive as the returned query `Promise` technically matches `toBeDefined`. `async`/`await` was added to ensure the test assertion awaits the query result, as well as fixes the following related log warning. ``` A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them. ```
- Loading branch information