GetJobber / atlantis

🔱 Atlantis
https://atlantis.getjobber.com
MIT License
25 stars 30 forks source link

fix(components): Mock popper to prevent act warnings in test suites #1967

Closed jdeichert closed 1 month ago

jdeichert commented 2 months ago

Motivations

Popper internally calls forceUpdate which leads to a re-render outside of React's normal lifecycle. This causes testing-library to rightfully throw act warnings in various test suites.

After digging into this, the common recommendation is to mock popper in tests.

NOTE: The Tooltip test suite has certain expectations around popper behaviour so I did not mock it there.

Changes

Fixed

Before / After

Before this change, when running this Combobox test case, there is an act warning in the console. After, there are no act warnings.

Screenshot 2024-07-25 at 11 27 25 AM Screenshot 2024-07-25 at 11 27 17 AM

Testing

  1. Run the combobox test suite and observe zero act warnings in the console.
  2. Disable the mock at the top of that suite and you'll see 1 act warning.

Feel free to verify the other suites I updated all contain zero act warnings.

Changes can be tested via Pre-release

cloudflare-workers-and-pages[bot] commented 2 months ago

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9682198
Status: âœ…  Deploy successful!
Preview URL: https://7381f717.atlantis.pages.dev
Branch Preview URL: https://cleanup-mock-popper-to-preve.atlantis.pages.dev

View logs