Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroneous react-dom usage in native tests #37921

Merged

Commits on Jan 12, 2022

  1. 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`.
    dcalhoun committed Jan 12, 2022
    Configuration menu
    Copy the full SHA
    f943fe4 View commit details
    Browse the repository at this point in the history
  2. 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.
    ```
    dcalhoun committed Jan 12, 2022
    Configuration menu
    Copy the full SHA
    07789a9 View commit details
    Browse the repository at this point in the history