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

Jest test fail when upgrading from v13.8.0 to v13.9.0 #12508

Closed
pkrucz00 opened this issue Aug 6, 2024 · 3 comments
Closed

Jest test fail when upgrading from v13.8.0 to v13.9.0 #12508

pkrucz00 opened this issue Aug 6, 2024 · 3 comments
Labels
Bug Something is broken and not working as intended in the system. untriaged

Comments

@pkrucz00
Copy link

pkrucz00 commented Aug 6, 2024

Summary

A lot of tests in our app fail after upgrading the polaris version from 13.8.0 to 13.9.0 with an error:

ReferenceError: ResizeObserver is not defined

This should not happen after a minor upgrade.

Expected behavior

The tests pass after an minor upgrade.

Actual behavior

PlacementForm › fetches placement data if placement is edited

    ReferenceError: ResizeObserver is not defined

      94 |     (ReactRouterDom.useParams as jest.Mock).mockReturnValue({ id: '1' });
      95 |
    > 96 |     act(() => {
         |        ^
      97 |       renderComponent();
      98 |     });
      99 |     await new Promise(process.nextTick);

      at ../../node_modules/@shopify/polaris/build/cjs/components/Popover/Popover.js:97:22
      at commitHookEffectListMount (../../node_modules/react-dom/cjs/react-dom.development.js:23189:26)
      at commitPassiveMountOnFiber (../../node_modules/react-dom/cjs/react-dom.development.js:24970:11)
      at commitPassiveMountEffects_complete (../../node_modules/react-dom/cjs/react-dom.development.js:24930:9)
      at commitPassiveMountEffects_begin (../../node_modules/react-dom/cjs/react-dom.development.js:24917:7)
      at commitPassiveMountEffects (../../node_modules/react-dom/cjs/react-dom.development.js:24905:3)
      at flushPassiveEffectsImpl (../../node_modules/react-dom/cjs/react-dom.development.js:27078:3)
      at flushPassiveEffects (../../node_modules/react-dom/cjs/react-dom.development.js:27023:14)
      at performSyncWorkOnRoot (../../node_modules/react-dom/cjs/react-dom.development.js:26115:3)
      at flushSyncCallbacks (../../node_modules/react-dom/cjs/react-dom.development.js:12042:22)
      at commitRootImpl (../../node_modules/react-dom/cjs/react-dom.development.js:26998:3)
      at commitRoot (../../node_modules/react-dom/cjs/react-dom.development.js:26721:5)
      at finishConcurrentRender (../../node_modules/react-dom/cjs/react-dom.development.js:26020:9)
      at performConcurrentWorkOnRoot (../../node_modules/react-dom/cjs/react-dom.development.js:25848:7)
      at flushActQueue (../../node_modules/react/cjs/react.development.js:2667:24)
      at act (../../node_modules/react/cjs/react.development.js:2582:11)
      at ../../node_modules/@testing-library/react/dist/act-compat.js:47:25
      at Object.<anonymous> (src/components/PlacementForm/__tests__/index.test.tsx:96:8)
      ```

### Steps to reproduce

1. Create tests with Polaris elements and run them

### Are you using React components?

Yes

### Polaris version number

13.9.0

### Browser

_No response_

### Device

MacBook
@pkrucz00 pkrucz00 added Bug Something is broken and not working as intended in the system. untriaged labels Aug 6, 2024
@pkrucz00
Copy link
Author

The problem still persists. Could you take a look at this issue? This prevents us from using the newest version of the Polaris dependency.

@dpanov
Copy link

dpanov commented Aug 27, 2024

@pkrucz00, some Polaris components now use ResizeObserver, so you'll need to mock it for your tests.

  global.ResizeObserver = jest.fn().mockImplementation(() => ({
    observe: jest.fn(),
    unobserve: jest.fn(),
    disconnect: jest.fn(),
  }));

Add this in the file that you pass to setupFilesAfterEnv in your jest.config.js and it should do the job.

@pkrucz00
Copy link
Author

OK, this helped. Thank you!

@dpanov dpanov closed this as completed Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken and not working as intended in the system. untriaged
Projects
None yet
Development

No branches or pull requests

2 participants