📝 Disallow conditional expects.
💼recommended config. This rule warns in the 🌐 all config.
This rule aims to prevent false positive test results by highlighting conditional expect statements.
Examples of incorrect code for this rule:
test('foo', () => {
if (false) {
expect(1).toBe(1)
}
})
test.for([null, { bar: 'baz' }])('quux', (value) => {
const expected = value === null ? expected : expect.stringContaining(expected)
expect(actual).toEqual(expected)
})Examples of correct code for this rule:
test('foo', () => {
expect(1).toBe(1)
})
test.for([null, expect.objectContaining({ bar: 'baz' })])(
'quux',
(expected) => {
expect(actual).toEqual(expected)
},
)| Name | Description | Type |
|---|---|---|
expectAssertions |
Enable/disable whether expect.assertions() is taken into account | Boolean |
{
"rules": {
"vitest/no-conditional-expect": ["error", { "expectAssertions": true }]
}
}Enable/disable whether to take the usage of expect.assertions() into account. Setting this to true will allow conditional expressions only if a call to expect.assertions() is also made.
test('foo', () => {
expect.assertions(1)
if (true) {
expect(1).toBe(1)
}
})