@@ -20,8 +20,56 @@ or when a matcher function was not called, e.g.:
2020expect (true ).toBeDefined ;
2121```
2222
23+ or when an async assertion was not ` await ` ed or returned, e.g.:
24+
25+ ``` js
26+ expect (Promise .resolve (' Hi!' )).resolves .toBe (' Hi!' );
27+ ```
28+
2329This rule is enabled by default.
2430
31+ ## Options
32+
33+ ``` js
34+ {
35+ type: ' object' ,
36+ properties: {
37+ alwaysAwait: {
38+ type: ' boolean' ,
39+ default: false ,
40+ },
41+ },
42+ additionalProperties: false ,
43+ }
44+ ```
45+
46+ ### ` alwaysAwait `
47+
48+ Enforces to use ` await ` inside block statements. Using ` return ` will trigger a
49+ warning. Returning one line statements with arrow functions is _ always allowed_ .
50+
51+ Examples of ** incorrect** code for the { "alwaysAwait": ** true** } option:
52+
53+ ``` js
54+ // alwaysAwait: true
55+ test (' test1' , async () => {
56+ await expect (Promise .resolve (2 )).resolves .toBeDefined ();
57+ return expect (Promise .resolve (1 )).resolves .toBe (1 ); // `return` statement will trigger a warning
58+ });
59+ ```
60+
61+ Examples of ** correct** code for the { "alwaysAwait": ** true** } option:
62+
63+ ``` js
64+ // alwaysAwait: true
65+ test (' test1' , async () => {
66+ await expect (Promise .resolve (2 )).resolves .toBeDefined ();
67+ await expect (Promise .resolve (1 )).resolves .toBe (1 );
68+ });
69+
70+ test (' test2' , () => expect (Promise .resolve (2 )).resolves .toBe (2 ));
71+ ```
72+
2573### Default configuration
2674
2775The following patterns are considered warnings:
@@ -33,6 +81,12 @@ expect('something', 'else');
3381expect (' something' );
3482expect (true ).toBeDefined ;
3583expect (Promise .resolve (' hello' )).resolves ;
84+ expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' );
85+ Promise .resolve (expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' ));
86+ Promise .all ([
87+ expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' ),
88+ expect (Promise .resolve (' hi' )).resolves .toEqual (' hi' ),
89+ ]);
3690```
3791
3892The following patterns are not warnings:
@@ -41,5 +95,12 @@ The following patterns are not warnings:
4195expect (' something' ).toEqual (' something' );
4296expect ([1 , 2 , 3 ]).toEqual ([1 , 2 , 3 ]);
4397expect (true ).toBeDefined ();
44- expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' );
98+ await expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' );
99+ await Promise .resolve (
100+ expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' ),
101+ );
102+ await Promise .all (
103+ expect (Promise .resolve (' hello' )).resolves .toEqual (' hello' ),
104+ expect (Promise .resolve (' hi' )).resolves .toEqual (' hi' ),
105+ );
45106```
0 commit comments