Assertion API
Vitest bundles @testing-library/jest-dom library to provide a wide range of DOM assertions out of the box. For detailed documentation, you can read the jest-dom readme:
toBeDisabledtoBeEnabledtoBeEmptyDOMElementtoBeInTheDocumenttoBeInvalidtoBeRequiredtoBeValidtoBeVisibletoContainElementtoContainHTMLtoHaveAccessibleDescriptiontoHaveAccessibleErrorMessagetoHaveAccessibleNametoHaveAttributetoHaveClasstoHaveFocustoHaveFormValuestoHaveStyletoHaveTextContenttoHaveValuetoHaveDisplayValuetoBeCheckedtoBePartiallyCheckedtoHaveRoletoHaveErrorMessage
If you are using TypeScript or want to have correct type hints in expect, make sure you have either @vitest/browser/providers/playwright or @vitest/browser/providers/webdriverio specified in your tsconfig depending on the provider you use. If you use the default preview provider, you can specify @vitest/browser/matchers instead.
json
{
"compilerOptions": {
"types": [
"@vitest/browser/matchers"
]
}
}json
{
"compilerOptions": {
"types": [
"@vitest/browser/providers/playwright"
]
}
}json
{
"compilerOptions": {
"types": [
"@vitest/browser/providers/webdriverio"
]
}
}