DEV Community

Cover image for Autopsy #07: 412 Green Tests and a Dead Menu Button
frontend.rocks
frontend.rocks

Posted on Edited on Originally published at frontend.rocks

Autopsy #07: 412 Green Tests and a Dead Menu Button

412 green checks in 11 seconds

Karim tidied up the mobile promotional banner wrapper and added a touchstart scroll lock for the navigation drawer so background content would not drift while the menu was open. Inès's suite of 412 Vitest + JSDOM tests ran in 11 seconds. Every single check was green, the PR diff looked harmless, and it merged cleanly before standup.

Twenty minutes after deploy, Nadia messaged #frontend to say nobody on a phone could open the main navigation menu anymore. She dropped two customer screenshots showing the menu icon sitting there with nothing happening on tap. We checked RUM telemetry: nav_dropdown_open events on viewports under 768 px had dropped from 14,200 per hour to zero. Not low. Exactly zero.

Desktop users saw nothing wrong, mobile bounce rate jumped 38%, and CI was still 100% green.

Adding a 413th green test

Karim looked at the header CSS, assumed the dropdown was painting behind the promo bar, bumped .dropdown-menu to z-index: 9999, and wrote test number 413 to prove the trigger worked:

fireEvent.click(screen.getByTestId('nav-trigger'));
expect(screen.getByTestId('nav-drawer')).toBeVisible();
Enter fullscreen mode Exit fullscreen mode

All 413 tests passed in 11 seconds. We shipped the hotfix and waited for the telemetry graph to recover. Mobile nav_dropdown_open events stayed at zero.

What JSDOM never tells you

When Inès opened the site on a real phone from her drawer with remote DevTools attached, the bug took ten seconds to find. She tapped the menu button, inspected the element under her finger, and saw .promo-banner-backdrop highlighted across the entire top half of the screen.

The transparent .promo-banner-backdrop was closed with opacity: 0, without pointer-events: none or inert. In a real Render Tree, a pointer tap at coordinates (x, y) runs geometric hit-testing from front to back and lands on the invisible backdrop sitting over the header. Setting opacity: 0 hides the pixels; it does not remove the box from pointer hit-testing.

In a simulated DOM like JSDOM, there is no CSS layout engine at all. Every getBoundingClientRect() returns { top: 0, left: 0, width: 0, height: 0 }, and fireEvent.click(node) dispatches the event straight onto node without checking whether another box is covering it. As far as JSDOM was concerned, the backdrop and the button did not even share a coordinate system.

Passive touch listeners and fake timers

That was only half of what JSDOM hid. Karim's new window.addEventListener('touchstart', (e) => e.preventDefault()) lacked { passive: false }. Because modern browsers treat document-level passive event listeners as the default for touch events so scrolling never stalls behind JavaScript, preventDefault() was ignored with a console warning that JSDOM never emits either.

Meanwhile, vi.useFakeTimers() in the async test suite skipped right over a 300 ms CSS transition race that left the drawer closed on rapid taps, and querying by data-testid instead of accessibility tree queries hid the fact that aria-expanded never toggled and screen-reader users could not even tell whether the menu was open or closed.

Fixing the backdrop and moving to a real engine

We fixed the backdrop by adding inert and pointer-events: none whenever the banner is closed, replaced the global touchstart listener with overscroll-behavior: contain on the drawer, and moved the critical mobile navigation checks into Playwright using page.getByRole('button', { name: 'Menu' }).

We also added a check that verifies aria-expanded flips from "false" to "true", focus moves cleanly into the drawer, and a user can navigate to at least one category link without hitting an invisible layer. In JSDOM, those assertions had been mocked or bypassed; in Chromium and WebKit at 390x844, the browser exercises the real CSS box tree, real stacking contexts, and real compositor touch routing on every pull request.

The { force: true } trap

First try in Playwright: the new browser test passed even when we intentionally left .promo-banner-backdrop broken on a test branch.

Someone had copied a helper that called .click({ force: true }). In Playwright, { force: true } disables the actionability check that verifies no other element intercepts the pointer at the target coordinates. It turns a real browser test back into JSDOM with a slower startup time. The moment we removed { force: true }, Playwright failed immediately and named .promo-banner-backdrop as the exact element intercepting the click at (342, 34).

What stayed in the codebase

JSDOM verifies that your function runs when you call it; a real browser verifies that a human finger can reach the button.

We now run 410 JSDOM unit tests and 6 real-browser tests, and those 6 are the ones that wake us up before Nadia does. Within two hours of deploying the fix, nav_dropdown_open climbed back to 14,400 events per hour and mobile bounce rate returned to baseline.


Interactive Simulator: Launch the live green-ci-broken-prod-jsdom lab on frontend.rocks →

Top comments (0)