Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940import { beforeEach, expect, test } from 'vitest'import { page } from 'vitest/browser'
beforeEach(() => { document.body.innerHTML = ''})
test('expect.element pass', async () => { document.body.innerHTML = '<button>Hello</button>' await expect.element(page.getByRole('button')).toHaveTextContent('Hello')})
test('expect.element fail', async () => { document.body.innerHTML = '<button>Hello</button>' await expect.element(page.getByRole('button'), { timeout: 100 }).toHaveTextContent('World')})
test('failure', async () => { document.body.innerHTML = '<button>Hello</button>' throw new Error('Test failure')})
test('click', async () => { document.body.innerHTML = '<button>Hello</button>' await page.getByRole('button').click()})
test('click fail', async () => { document.body.innerHTML = '<button>Hello</button>' try { await page.getByRole('button', { name: 'Missing' }).click({ timeout: 100 }) } catch (e) { // error messages are different by providers. // this is irrelevant since this is a test for action trace metadata e.message = 'Click failed (normalized)' throw e }})