2026.10.28

Choose unit, jsdom, browser, and real-API tests by purpose

Four questions for choosing a frontend test based on what it needs to guarantee.

While I’m at it, I’d like to share how I decide which frontend tests to use, including E2E tests…!

When writing tests, I first decide what I want to check, then choose between unit tests, component tests (jsdom), and E2E tests!

① Check the result of logic → Unit tests Use these to check calculations, conditional branches, data transformations, and validation rules themselves for a given input! If I can check something without rendering a screen, I start here. Example: Does the validation rule reject an input that exceeds the character limit?

② Check how the screen responds to user actions → Component tests (jsdom) Use these to check component state and rendering: input, clicks, error messages, and enabled or disabled buttons. Example: When a user enters text exceeding the character limit, does an error appear and does the submit button become disabled?

Even for the same validation feature, I test the rule itself with unit tests and the screen’s display and response to actions with component tests. Keep in mind that jsdom cannot verify layout or behavior specific to a real browser.

③ Check layout or behavior specific to a real browser → E2E tests (sometimes with an API mock) Use these to check layout, interactions in the browser, and navigation across multiple screens. Example: At a phone-sized viewport, are the action buttons fully visible and clickable?

Even when using a real browser, you can mock the API depending on what you want to check. You do not need to connect to the backend every time. However, adding mocks carelessly can lead to mocking tests that should not be mocked, so be careful.

④ Check that the frontend actually connects through to the backend → E2E tests (real API) Authenticate, interact with the screen, call the real API, save data, and see the result reflected on screen. I use E2E tests for important user scenarios that only work when this entire flow is connected. Important failure scenarios are also covered, while detailed input variations and conditional branches are left to unit and component tests.

To sum up, these are the four questions I consider! ・Can this be checked through logic alone? ・Do I need to check the screen’s display or response to actions? ・Do I need a real browser? ・Do I need to connect to the backend?

I recommend choosing tests by asking, “What do I need to run to guarantee what I want to check?”

https://x.com/suna_gaku/status/2115014173419810957

Addendum: Dropping “just put it in E2E” took CI from 2 hours to 5 minutes (Zenn)

I wrote an article about how CI went from 2 hours to 5 minutes once I stopped doing “just put it in E2E”!

In Lovady, the relationship-advice app I build as a personal project, I kept putting AI-written tests into E2E for now, and as a result…

  • 1,726 Playwright E2E tests across 5 browsers
  • All of them ran on every PR, taking over 2 hours each time…
  • 25 runs over 3 days, and only 1 succeeded

It had become a complete bottleneck for development, so while reviewing it together with Codex, I organized and wrote up my criteria for deciding where each test belongs and a way to safely reduce E2E tests!

If you are interested, please take a look!

Dropping “just put it in E2E” took CI from 2 hours to 5 minutes (Zenn, Japanese)

https://x.com/suna_gaku/status/2116760105844883616