Skip to content

Commit

Permalink
Feat/expect expect issues (#328)
Browse files Browse the repository at this point in the history
* chore(trying to fix expect): expect-expect

* fix(expect-expect): fixed expect rule

* chore(conflicts): fixed conflicts
  • Loading branch information
veritem authored Dec 17, 2023
1 parent 0249131 commit bf5cb08
Show file tree
Hide file tree
Showing 7 changed files with 864 additions and 428 deletions.
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

0 comments on commit bf5cb08

Please sign in to comment.