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

Headless v2 makes resizeObserver mandatory for testing #3268

Closed
razzeee opened this issue Jun 4, 2024 · 2 comments
Closed

Headless v2 makes resizeObserver mandatory for testing #3268

razzeee opened this issue Jun 4, 2024 · 2 comments
Assignees

Comments

@razzeee
Copy link

razzeee commented Jun 4, 2024

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

v2.0.4

What browser are you using?

jest

Describe your issue

After migrating to headless ui v2, most tests seem to fail due to us not having a resizeObserver.

I can get around this by mocking this globally:

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

Comments here also suggest this, but I have never seen it on v1 #2832 (reply in thread)

@RobinMalfait RobinMalfait self-assigned this Jun 7, 2024
@RobinMalfait
Copy link
Member

Hey!

The good news is that ResizeObserver has been around for years now and it's available in all major browsers. Unfortunately, it's not available in jsdom yet (jsdom/jsdom#3368), which is why you are seeing these issues.

You can do a few things:

  1. Use the polyfill you have, it's currently not used for something super critical (used to know when a button moved due to scroll or tab) and you likely won't see a change in the tests, so it's safe to polyfill.
  2. Use the real polyfill:
import ResizeObserver from 'resize-observer-polyfill'
global.ResizeObserver = ResizeObserver
  1. Try to use tests against a real browser instead using something like Playwright.

So going to close this for now because I don't consider this a bug of Headless UI. If we rely on new features of JavaScript that aren't available in major browsers we will make sure to polyfill them internally.

Hope this helps!

@razzeee
Copy link
Author

razzeee commented Jun 7, 2024

To make it clear, I don't think this is a bug of Headless UI too. It's a bug in the v2 docs, which don't mention this.

corneliusroemer added a commit to loculus-project/loculus that referenced this issue Jun 30, 2024
…2200)

* chore(deps): bump @headlessui/react from 1.7.19 to 2.1.1 in /website

Bumps [@headlessui/react](https://github.com/tailwindlabs/headlessui/tree/HEAD/packages/@headlessui-react) from 1.7.19 to 2.1.1.
- [Release notes](https://github.com/tailwindlabs/headlessui/releases)
- [Changelog](https://github.com/tailwindlabs/headlessui/blob/main/packages/@headlessui-react/CHANGELOG.md)
- [Commits](https://github.com/tailwindlabs/headlessui/commits/@headlessui/react@v2.1.1/packages/@headlessui-react)

---
updated-dependencies:
- dependency-name: "@headlessui/react"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(website): migrate headless ui to use DialogPanel instead of Dialog.Overlay

See https://github.com/tailwindlabs/headlessui/releases/tag/%40headlessui%2Freact%40v1.6.0 for migration guide

* chore(website): address Combobox nullable breaking change for headless-ui v2

see tailwindlabs/headlessui#3064

* chore(website): appease typescript for headlessui v2 upgrade for nullable combobox

Headlessui v2 makes it necessary to handle null input for combobox.

See tailwindlabs/headlessui#3064

* chore(website): address headlessui v2 deprecation warnings due to renamings

* chore(website): use focus instead of deprecated active, headlessui v2 migration

see https://github.com/tailwindlabs/headlessui/releases/tag/%40headlessui%2Freact%40v2.0.0#user-content-upgrading-from-v1

* chore(website): mock ResizeObserver, neccesary for headlessui v2

see tailwindlabs/headlessui#3268

* Use new `immediate` feature of headlessui v2

* Fix flaky test by waiting for modal to be removed

* fix failing test by using userEvent.click instead of fireEvent.click

* chore: address warnings/lints

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cornelius Roemer <cornelius.roemer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants