Add a Popover API shim to the Jest DOM shims

What does this MR do and why?

Adds a small Popover API shim to our Jest DOM shims (spec/frontend/__helpers__/dom_shims/popover.js), ahead of time and as a no-op for now.

Why now, when nothing uses it?

The upcoming GlTooltip in @gitlab/ui is built on the native Popover API: gitlab-org/gitlab-services/design.gitlab.com!6294 (merged). jsdom, which runs our frontend specs, doesn't implement that API (https://github.com/jsdom/jsdom/issues/3721), so specs that render the new GlTooltip for real (without the global @gitlab/ui mock) would throw.

The @gitlab/ui upgrade has to come with this shim. It's tested in the integration branch (!255018), which carries exactly this commit. Merging the shim separately keeps that upgrade small and reviewable. It's one of several prep MRs, after !262798 (merged).

What the shim does

It behaves like the shim in @gitlab/ui's own specs:

  • showPopover(), hidePopover() and togglePopover() track the open state in a data-popover-open attribute and dispatch toggle events.
  • Repeated calls are ignored, and elements without a popover attribute throw NotSupportedError, as in browsers.
  • togglePopover() returns whether the popover is now open.

Two deliberate differences:

  • It also answers matches(':popover-open'). The jsdom version here (20) doesn't throw on that selector, it always returns false. Without the patch, GlTooltip would consider every tooltip closed and never hide it. @gitlab/ui's specs run jsdom 26, where the selector throws and GlTooltip falls back to data-popover-open.
  • It doesn't define the popover property. Vue 3 sets an attribute as a DOM property when the element has one, so defining it would stop popover="manual" from rendering as an attribute in the Vue 3 specs.

Like the other jsdom shims, it lives in dom_shims, which both jest and jest-integration load. spec/frontend/__helpers__/dom_shims/popover_spec.js covers it.

Why it's a no-op today

  • Nothing in app, ee/app, our specs or templates calls the Popover API or renders a popover attribute. The showPopover/hidePopover names that exist are Vue component methods, not DOM calls.
  • The current @gitlab/ui, including its vendored bootstrap-vue, doesn't use it.
  • The only dependency loaded in specs that touches it is @floating-ui/dom, which calls element.matches(':popover-open'). That still returns false, because nothing is ever shown through the shim.

Checked locally on master:

  • I ran 202 spec files with and without the shim: sidebar, super sidebar, filtered search, diffs components, tooltips, user popover and cycle analytics components. Every test result was identical, in both Vue versions (3538 results with Vue 2, 3385 with Vue 3). The failures in those runs were identical too, and come from my local setup (missing generated fixtures, plus local Vue 3 issues).
  • In the integration branch, with the new GlTooltip, the real component and directive render popover="manual" in both Vue versions, and show, hide and hover work.

No production code changes.

References

How to set up and validate locally

yarn jest spec/frontend/__helpers__/dom_shims/popover_spec.js
VUE_VERSION=3 yarn jest spec/frontend/__helpers__/dom_shims/popover_spec.js

The full Jest pipeline of this MR is the real check that nothing else changes.

Edited by Thomas Hutterer

Merge request reports

Loading
Loading