-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add Documentation for valid-expect-in-promise Rule (#581)
* docs: valid-expect-in-promise * docs: update README * refactor: typo and remove
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Require promises that have expectations in their chain to be valid (`vitest/valid-expect-in-promise`) | ||
|
||
⚠️ This rule _warns_ in the 🌐 `all` config. | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
This rule flags any promises within the body of a test that include expectations that have either not been returned or awaited. | ||
|
||
The following patterns is considered warning: | ||
|
||
```js | ||
test('promise test', async () => { | ||
something().then((value) => { | ||
expect(value).toBe('red'); | ||
}); | ||
}); | ||
|
||
test('promises test', () => { | ||
const onePromise = something().then((value) => { | ||
expect(value).toBe('red'); | ||
}); | ||
const twoPromise = something().then((value) => { | ||
expect(value).toBe('blue'); | ||
}); | ||
|
||
return Promise.any([onePromise, twoPromise]); | ||
}); | ||
``` | ||
|
||
The following pattern is not warning: | ||
|
||
```js | ||
|
||
test('promise test', async () => { | ||
await something().then((value) => { | ||
expect(value).toBe('red'); | ||
}); | ||
}); | ||
|
||
test('promises test', () => { | ||
const onePromise = something().then((value) => { | ||
expect(value).toBe('red'); | ||
}); | ||
const twoPromise = something().then((value) => { | ||
expect(value).toBe('blue'); | ||
}); | ||
|
||
return Promise.all([onePromise, twoPromise]); | ||
}); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters