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

Test Mermaid diagrams in two layers: use Mermaid’s parse API to catch invalid syntax, then compare a rendered diagram or the actual page containing it against a reviewed visual baseline. Syntax validation cannot detect an unexpected layout change; a screenshot comparison cannot explain whether the cause is Mermaid source, fonts, CSS, browser settings, or the rendering environment.

Choose what the visual test should represent

Start by deciding which output you need to keep stable. A standalone render is appropriate when the deliverable is an exported SVG, PNG, or PDF. A browser screenshot of the documentation or application page is more representative when the production experience depends on Mermaid initialization, page CSS, theme selection, viewport constraints, or surrounding layout.

  • Test the artifact: Render the Mermaid definition with Mermaid CLI and compare the generated file when the exported diagram itself is the product.
  • Test the integrated page: Open the real route in a browser and capture the diagram or its container when you need to cover the presentation users see.

Mermaid documents both browser rendering and its render API, while Mermaid CLI offers a separate file-rendering route: Mermaid usage documentation and Mermaid CLI README.

Validate Mermaid syntax before comparing images

Use mermaid.parse(text, parseOptions) to check a definition without rendering a graph. A valid definition returns its diagram type; invalid syntax throws unless errors are suppressed. Treat a parse failure as a test failure or report it clearly before starting screenshot comparison. Parsing checks syntax only—it does not establish that the resulting diagram looks right.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
The IXL Ultimate 3rd Grade Math Workbook, Activity Book for Kids Ages 8-9 Covering Addition, Subtraction, Multiplication, Division, Fractions, Geometry, and More Mathematics (IXL Ultimate Workbooks)
  • Carefully designed questions: Ensuring a solid understanding of concepts
  • Engaging activities: Offering a mix of enjoyable exercises
  • Problem-solving techniques: Providing strategies for tackling challenges
  • Vibrant, full-color visuals: Enhancing learning with captivating illustrations

For example, in a test environment where Mermaid is available:

import mermaid from 'mermaid';

const definition = `
flowchart TD
  A[Source] --> B[Rendered diagram]
`;

await mermaid.parse(definition);

Adapt module setup and initialization to the Mermaid version and test runner already used by your project. Mermaid’s usage documentation describes the parse API and browser-side rendering: https://mermaid.js.org/config/usage.html.

Render a standalone diagram with Mermaid CLI

For file-based tests, Mermaid CLI accepts a Mermaid definition and can emit SVG, PNG, or PDF. Its basic command is:

Rank #2
YAFIYGI Eye Chart Snellen and Rosenbaum Combo Vision Test Card for Exams Near Point Charts for Professional and Pediatric Use 2 in 1 Eye Exam Chart Set Kids Gifts Eye Exams and Vision Screening 2 PCS
  • Dual Functionality: Our Pocket Eye Chart set includes both the 2 eye charts, offering a versatile solution for measuring visual acuity at a distance and in limited spaces. This 2-in-1 design caters to various vision testing needs
  • Compact and Convenient: Sized at 6.5*3.5 inches, these pocket eye charts are designed for portability. Whether you're a professional optometrist, student, or need a handy tool for vision tests on the go, our compact pocket eye chart set fits conveniently in your pocket 
  • Color Vision Test: The eye chart features Red and Green color bars, providing an easy and helpful color vision test. This additional feature enhances the versatility of our pocket eye chart set, making it suitable for a range of vision examinations
  • Durable and Washable: Crafted from durable plastic, our pocket eye charts are built to last. The washable material ensures easy maintenance and hygiene, making them ideal for repeated use in optometry practices, schools, and offices
  • Pupil Gauge and Non-Reflective:The plastic pocket eye chart includes a pupil gauge, adding practicality to vision examinations. The non-reflective surface ensures accurate readings. This set is a reliable tool for professionals and a handy resource for quick vision assessments
mmdc -i input.mmd -o output.svg

Choose the output format that matches the artifact you ship or want to review. The CLI can also process Markdown with embedded Mermaid blocks and produce transformed Markdown that references generated SVG files. It supports theme and background options; keep renderer configuration controlled so a changed theme or background is not mistaken for an accidental regression.

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

Pin Mermaid and renderer versions in your project and update them intentionally. A dependency update can change output even when the diagram source is unchanged. The CLI documentation describes commands, formats, and options: Mermaid CLI README.

Compare the real page with Playwright

If users encounter diagrams inside a browser page, a Playwright screenshot assertion can compare the rendered SVG or its containing element with a checked-in baseline. The following is an illustrative test sketch; adjust the route, selector, and readiness condition to match your application.

import { test, expect } from '@playwright/test';

test('architecture diagram stays visually stable', async ({ page }) => {
  await page.goto('/docs/architecture');
  const diagram = page.locator('.mermaid svg');
  await expect(diagram).toBeVisible();
  await expect(diagram).toHaveScreenshot('architecture-diagram.png');
});

Wait for Mermaid rendering to finish before capturing. Depending on the application, that may mean waiting for the target SVG to appear, checking a page-specific ready state, or waiting for fonts and other layout-affecting assets to load. A selector such as .mermaid svg is not universal: use the markup your integration actually renders.

On the initial run, Playwright can create missing baselines. Review those images before committing them. When a later comparison differs, inspect the image diff and update the expected snapshot only when the visual change is intended. Playwright documents toHaveScreenshot() and the --update-snapshots option in its visual comparisons guide.

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

Keep screenshots stable and useful

Browser rendering can vary with operating system, browser version, settings, hardware, power source, and headless mode. Generate and compare snapshots in the same environment where practical; otherwise, platform-specific differences can obscure meaningful changes. Fix the viewport and avoid including unrelated dynamic content in the captured region.

Rank #4
Morning and Bedtime Routine Chart with 12 visual symbols pecs cards by Create Visual Aids to support routine, transition for children, autism, aspergers, ADHD, speech and language delay.
  • Creating calmer and happier mornings and bedtimes for the whole family by showing your child what they need to do to get ready.
  • Encourages independence and therefore boosts self esteem as children are no longer dependent on you reminding them what comes next.
  • Allows for processing time - the pictures, or pecs cards for autism, don't disappear like words do and therefore these are great for children with special educational needs, autism, ADHD, speech and language delay, ASD.
  • Eliminates the need for you to nag - children can see what they need to do for themselves in this routine chart.
  • Pictures cards can be moved around thanks to being attached using VELCRO Brand hook and loop, meaning you can order the routine to suit your family.

Choose test cases based on the experience your project supports. There is no universal matrix; include only combinations where a visual difference matters to users.

Test axis Include it when
Theme The site or diagram offers light and dark modes, or the selected theme changes what users see.
Browser or operating system Cross-browser or cross-platform presentation is a supported requirement. Use separate baselines where output legitimately differs.
Viewport Size changes may affect fit, clipping, wrapping, or legibility.
Fonts Your product supplies fonts or font-loading differences may affect diagram layout.

Playwright screenshot options can apply a stylesheet to filter volatile page elements. Use that narrowly: excluding genuinely changing content can reduce noise, but hiding the diagram or an important part of its presentation defeats the test.

Set pixel-difference tolerance deliberately

Playwright supports screenshot comparison options such as maxDiffPixels, and Playwright Test uses pixelmatch. A tolerance can help with small rendering noise, but a permissive threshold may hide a real change. Set it based on observed, reviewed behavior, document the reason in test configuration, and keep reviewing baseline diffs rather than treating tolerance as a substitute for review. See Playwright’s screenshot comparison options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right test layer

Approach Best for What it does not establish
Mermaid parse API Fast syntax validation before rendering. Whether layout or appearance is correct.
Mermaid CLI Generated SVG, PNG, or PDF files and Markdown conversion. Whether the full production browser integration renders as intended.
Playwright screenshot assertion Visual output in a browser page, including relevant integration and CSS. Why a difference occurred; that requires examining the diff and environment.

Mermaid’s project overview names Argos for pull-request visual regression testing and Applitools in its release process; the Mermaid CLI README also references Percy. These are examples of hosted review workflows, not requirements or a claim about current pricing or availability. For any visual test service, verify current terms directly. Mermaid’s overview is at mermaid.js.org; CLI references are in the Mermaid CLI README.

Troubleshoot common failures

  • Parse test fails: The definition may contain invalid Mermaid syntax. Surface the parse error first and fix the source before reviewing a screenshot.
  • Diagram selector is missing: The page may not have rendered the diagram yet, or the application may use different markup. Wait for the actual ready condition and inspect the page’s rendered DOM to choose a project-specific selector.
  • Screenshot differs after a dependency update: Check Mermaid, CLI, browser, and configuration changes. Decide whether the new output is intended before updating the baseline.
  • Differences appear only on some machines: Align operating system image, browser version, fonts, viewport, settings, and headless mode, or maintain distinct baselines for supported environments.
  • Unrelated page content causes failures: Capture the diagram or a focused container rather than the entire page, and filter only content that is genuinely volatile.
  • Tolerance hides a visible issue: Lower the threshold and inspect the diff; do not increase tolerance simply to make a failing test pass.

Or skip the browser setup

For a screenshot you can fetch with one request, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF through its website screenshot API. This does not replace a Playwright assertion against your actual production page; use it when a direct capture endpoint suits the check.

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 parameters. Cookie banners are accepted and removed before the shot, along with supported newsletter popups and chat widgets. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers identify the page verdict and billing status. An MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

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.

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