Skip to content
Latest

Vitest examples

Basic component screenshot

import { expect, test } from 'vitest';
import { page } from 'vitest/browser';
test('button', async () => {
document.body.innerHTML = '<button>Click me</button>';
await expect(page.getByRole('button')).toMatchScreenshot('button.png');
});

Variants with properties

Add variant to local signatureProperties or your cloud project’s matching settings to keep these on separate baselines.

await expect(page.getByRole('button')).toMatchScreenshot('button.png', {
properties: { variant: 'primary' }
});
await expect(page.getByRole('button')).toMatchScreenshot('button.png', {
properties: { variant: 'secondary' }
});

Hover or focus state

let button = page.getByRole('button');
await button.hover();
await expect(button).toMatchScreenshot('button-hover.png');

Full-page screenshot

await expect(page).toMatchScreenshot('page.png', {
fullPage: true
});

Check status inside a test

import { getVizzlyStatus } from '@vizzly-testing/vitest';
let status = getVizzlyStatus();

Tip

Use stable metadata for variants such as theme or state. Only add keys to baseline matching when those variants need separate baselines.

Next steps