eslint-plugin-jest
Version:
ESLint rules for Jest
40 lines (29 loc) ⢠1.06 kB
Markdown
š§ This rule is automatically fixable by the
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
<!-- end auto-generated rule header -->
`Jest` can handle fulfilled/rejected promisified function call normally but
occassionally, engineers wrap said function in another `async` function that is
excessively verbose and make the tests harder to read.
This rule triggers a warning if `expect` is passed with an an `async` function
that has a single `await` call.
Examples of **incorrect** code for this rule
```js
it('wrong1', async () => {
await expect(async () => {
await doSomethingAsync();
}).rejects.toThrow();
});
it('wrong2', async () => {
await expect(async function () {
await doSomethingAsync();
}).rejects.toThrow();
});
```
Examples of **correct** code for this rule
```js
it('right1', async () => {
await expect(doSomethingAsync()).rejects.toThrow();
});
```