Skip to content

Latest commit

 

History

History
91 lines (64 loc) · 2.08 KB

expect-expect.md

File metadata and controls

91 lines (64 loc) · 2.08 KB

Enforce having expectation in test body (vitest/expect-expect)

💼 This rule is enabled in the ✅ recommended config.

Rule Details

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)
})

Type-testing

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.

Options

assertFunctionNames

{
  "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")
})

additionalTestBlockFunctions

{
  "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)
  })
})