This guide outlines the process of migrating from using Web Test Runner to Vitest Browser for testing web components created with Lit. For more details on browser mode, visit the Vitest guide.
This change stems from a desire to explore more popular and widely adopted options in the open-source world, such as Vite and Vitest.
It's interesting to see how Vitest Browser draws inspiration from many other tools, including Web Test Runner itself.
The Chai A11y aXe testing library can be used with Vitest.
test('a11y', async () => {
await assert.isAccessible(el);
});Vitest's snapshot feature combines very well with getDiffableHTML from @open-wc, providing a powerful way to test DOM structures meaningfully.
import {getDiffableHTML} from '@open-wc/semantic-dom-diff/get-diffable-html.js';
test('LIGHT DOM - Structure test', () => {
expect(getDiffableHTML(el, {ignoreAttributes: ['id']})).toMatchSnapshot('LIGHT DOM');
});For more details, refer to the snapshots - semantic-dom-diff documentation.
Scaffold generated using: