October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Test Your Web App in Dark Mode With Cypress

A Cypress dark-mode test should exercise the theme input your app actually uses and assert rendered output. Learn how to test a toggle, handle system preference, and keep visual checks repeatable.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test the theme input your app actually uses, then assert what the browser renders. For a theme toggle, click it and check the resulting theme state and styles. For an app that follows prefers-color-scheme: dark, set that preference through a browser setup you have verified for your Cypress and browser versions; the Cypress documentation covered here does not establish a specific command for forcing it. cy.viewport() changes dimensions, not color-scheme preference.

Choose the dark-mode behavior to test

App behavior What drives the theme What the test should verify Useful test scope
User-controlled theme An in-app toggle or menu action. The control changes the rendered theme; if the app promises persistence, the choice survives navigation or reload. End-to-end for the user flow and persistence; component testing for a controlled rendering check.
System-preference theme The browser’s color-scheme preference, commonly prefers-color-scheme. The app responds to a dark preference and renders expected dark styles. Component or end-to-end, depending on whether you need to test rendering alone or the full application.

Cypress component tests render CSS in a real browser and support checking rendered styles and interactions. Cypress also notes that browser dark-mode support and application theme-provider setup can make component rendering differ from production. For browser launch customization, Cypress documents general extension points such as launch arguments and preferences, but the cited guidance does not provide a verified dark-mode-specific recipe. See the Cypress component styling guide and cross-browser testing guide.

As an Amazon Associate I earn from qualifying purchases.

Test a user-facing theme toggle

Start with a deterministic page and stable selectors. The example below assumes your app exposes a button named “Dark mode” and a page element with a stable test ID. Replace those selectors and the expected values with the contract your application actually exposes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
describe('dark theme toggle', () => {
  it('renders the dark theme after the user selects it', () => {
    cy.visit('/settings/theme');

    cy.findByRole('button', { name: 'Dark mode' }).click();

    cy.get('[data-testid="app-shell"]')
      .should('have.attr', 'data-theme', 'dark');

    cy.get('[data-testid="page-title"]')
      .should('have.css', 'color', 'rgb(245, 245, 245)');
  });
});

This is a test pattern, not a drop-in test: it requires the Testing Library Cypress query command if you use findByRole, and the test ID, attribute, route, accessible name, and color must match your application. If you do not use Testing Library, use Cypress’s built-in cy.get() with a stable selector for the control and assert its accessible or visible result.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Check the rendered surface, not only a theme flag

A root attribute or class confirms that the app switched state, but not that its important content is legible. Add representative checks for the page background, primary text, links, borders, form controls, overlays, and at least one meaningful interactive state. Prefer stable selectors and user-visible behavior where possible; use computed styles when a visual property is the contract you need to protect.

Test persistence only when the app promises it

If the selected theme should persist, extend the flow by navigating to another page or reloading and checking the rendered theme again. This tests the behavior users rely on, rather than only whether the toggle changes a class in the current render.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Test a system-preference theme carefully

For a system-driven theme, the test must run in a browser environment that actually presents the intended color-scheme preference to the app. The Cypress documentation cited here describes browser launch customization generally; it does not establish a particular Cypress command or launch argument for emulating dark mode. Do not treat an unverified snippet as a supported Cypress API.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Confirm the Cypress and browser versions used in CI and locally.
  2. Choose a preference-setting mechanism supported by that browser and verify independently that the browser reports dark color scheme to the page.
  3. Run the app through that setup, then assert a visible theme result—such as a rendered background and text style—not merely the presence of CSS that could be inactive.
  4. Keep this environment setup separate from viewport sizing. A narrow viewport may be useful for responsive coverage, but resizing does not set the system color preference.

If you cannot verify preference emulation in the browser you run, do not claim that the test covers the system-preference branch. Cover the theme provider or CSS behavior in a controlled component test instead, and document the remaining browser-level gap.

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Separate viewport coverage from dark-mode coverage

cy.viewport() is for viewport dimensions and orientation. Cypress documents a default application viewport of 1000 by 660 pixels and says it resets to that default between tests. Use explicit dimensions for responsive checks, while treating color scheme as a separate input. See Cypress’s viewport command documentation.

it('keeps the dark layout usable at a narrow width', () => {
  cy.viewport(375, 812);
  cy.visit('/settings/theme');
  cy.findByRole('button', { name: 'Dark mode' }).click();

  cy.get('[data-testid="app-shell"]')
    .should('have.attr', 'data-theme', 'dark');
  cy.get('[data-testid="primary-action"]').should('be.visible');
});

The example checks a dark theme at a small viewport; it does not emulate a dark system preference. Set viewport dimensions in Cypress configuration or with cy.viewport(). Starting with Cypress 16.0.0, Cypress.config() cannot change viewport width or height during test execution; use cy.viewport() or test configuration instead. See Cypress configuration documentation.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make visual comparisons repeatable

Dark-mode screenshots are particularly sensitive to rendering differences in fonts, antialiasing, browser versions, and transient UI. For repeatable visual comparisons:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use the same browser, operating environment, and fixed viewport for baseline and comparison.
  • Use stable application data and control time-dependent content.
  • Wait for the page’s meaningful ready state before capturing.
  • Avoid taking a screenshot while animations or transitions are in progress.
  • Choose the test scope deliberately: a component image isolates a control or theme provider; a full-page image checks the combined page experience.

Cypress’s visual testing guidance discusses consistent environments, fixed viewports, dynamic content, and animation-related screenshot instability: Cypress visual testing.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Common failures and fixes

Symptom Likely cause What to do
The test changes viewport size but remains in light mode. Viewport dimensions do not emulate a color-scheme preference. Use the app’s theme toggle or a separately verified browser preference setup.
The root has a dark class, but text or controls are still light. The theme state changed, but some components or styles are not wired to it. Assert representative rendered surfaces and correct the missing theme styles or provider setup.
A component test renders differently from production. Browser dark-mode support or the app’s theme provider may differ between test and production setup. Align the test’s provider and browser environment with the intended behavior; use a full browser flow if that is what needs validation.
A screenshot comparison fails intermittently. Environment, data, time-dependent content, or animation differs between runs. Stabilize those inputs and capture after the page is ready and motion has stopped.
Changing viewport through Cypress.config() fails during a test. From Cypress 16.0.0, viewport width and height cannot be changed that way during test execution. Use cy.viewport() in the test or configure the viewport in test configuration.

Or skip the browser setup

For a screenshot of a rendered page, ScreenshotNeo can return an image with one GET request; it is not a replacement for Cypress assertions or a test of your app’s theme logic. For a controlled capture, set the target URL to a route that renders the desired theme state:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for free and get 1,000 screenshots a month with no card.

Frequently asked questions

Can a Cypress test confirm dark mode works across browsers?

Yes, if you run the relevant test in each browser you support and verify that the app renders the intended result there. Cypress documents cross-browser testing for Chrome-family browsers, Firefox, and WebKit; browser-specific preference setup still needs verification for the exact browser and version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should dark mode be tested in a component test or an end-to-end test?

Use a component test to isolate theme-provider or component rendering. Use an end-to-end test when the requirement includes the user’s toggle flow, navigation, or persistence. Many apps benefit from both scopes because they answer different questions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.