💼 This rule is enabled in the ✅ recommended
config.
all
config.
This rule aims to enforce having at least one expectation in test body to ensure that the test is actually testing something.
Examples of incorrect code for this rule:
test('myLogic', () => {
console.log('myLogic')
})
test('myLogic', () => {})
Examples of correct code for this rule:
test('myLogic', () => {
const actual = myLogic()
expect(actual).toBe(true)
})
If you're using Vitest's type-testing feature and have tests that only contain expectTypeOf
, you will need to enable typecheck
in this plugin's settings: Enabling type-testing.
{
"vitest/expect-expect": [
"error",
{
"assertFunctionNames": ["expect"],
"additionalTestBlockFunctions": []
}
]
}
An array of strings that are the names of the functions that are used for assertions. Function names can also be wildcard patterns like expect*
,function.**.expect
or expect.anything
.
The following is an example of correct code for this rule with the option assertFunctionNames
:
import CheckForMe from 'check-for-me'
test('myLogic', () => {
expect("myLogic").toBe("myOutput")
})
{
"rules": {
"vitest/expect-expect": [
"error",
{ "additionalTestBlockFunctions": ["checkForMe"] }
]
}
}
An array of strings that are the names of the functions that are used for test blocks. Function names can also be wildcard patterns like describe*
,function.**.describe
or describe.anything
.
The following is an example of correct code for this rule with the option additionalTestBlockFunctions
:
import CheckForMe from 'check-for-me'
checkForMe('myLogic', () => {
checkForMe('myLogic', () => {
const actual = myLogic()
expect(actual).toBe(true)
})
})