2020-05-15 05:33:08 +08:00
|
|
|
# Enforce having return statement when testing with promises (`valid-expect-in-promise`)
|
2020-03-07 11:45:40 +08:00
|
|
|
|
|
|
|
Ensure to return promise when having assertions in `then` or `catch` block of
|
|
|
|
promise
|
|
|
|
|
|
|
|
## Rule details
|
|
|
|
|
2020-09-13 06:19:45 +08:00
|
|
|
This rule looks for tests that have assertions in `then` and `catch` methods on
|
|
|
|
promises that are not returned by the test.
|
2020-03-07 11:45:40 +08:00
|
|
|
|
|
|
|
### Default configuration
|
|
|
|
|
|
|
|
The following pattern is considered warning:
|
|
|
|
|
|
|
|
```js
|
|
|
|
it('promise test', () => {
|
|
|
|
somePromise.then(data => {
|
|
|
|
expect(data).toEqual('foo');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
The following pattern is not warning:
|
|
|
|
|
|
|
|
```js
|
|
|
|
it('promise test', () => {
|
|
|
|
return somePromise.then(data => {
|
|
|
|
expect(data).toEqual('foo');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|