Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/expect expect issues #328

Merged
merged 4 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

<!-- end auto-generated rule header -->


## 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:

```js
test('myLogic', () => {
const actual = myLogic()
console.log('myLogic')
})

test('myLogic', () => {})
```

Examples of **correct** code for this rule:
Expand All @@ -25,15 +30,58 @@ test('myLogic', () => {

## Options

> Default: `expect`

Array of custom expression strings that are converted into a regular expression.
### `assertFunctionNames`

```json
{
"customExpressions": [
"expectValue",
"mySecondExpression"
"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`:

```js
import CheckForMe from 'check-for-me'
test('myLogic', () => {
expect("myLogic").toBe("myOutput")
})
```


### `additionalTestBlockFunctions`


```json
{
"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`:

```js
import CheckForMe from 'check-for-me'
checkForMe('myLogic', () => {
checkForMe('myLogic', () => {
const actual = myLogic()
expect(actual).toBe(true)
})
})
```

10 changes: 9 additions & 1 deletion fixtures/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"extends": [
"plugin:vitest/all"
"plugin:vitest/recommended"
],
"rules": {
"vitest/expect-expect": [
"error",
{
"customExpressions": [
"expect.*"
]
}
],
"vitest/unbound-method": "off"
}
}
Loading