Skip to content

Commit e6f4f8a

Browse files
authoredJan 15, 2022
feat(prefer-expect-assertions): support requiring only if expect is used in a loop (#1013)
* feat(prefer-expect-assertions): support requiring only if `expect` is used in a loop * test(prefer-expect-assertions): add cases for each * chore(prefer-expect-assertions): add default value for `onlyFunctionsWithExpectInLoop` option * test(prefer-expect-assertions): adjust some cases * fix(prefer-expect-assertions): report expects in loops in functions in tests * test(prefer-expect-assertions): format cases a bit
1 parent 237b551 commit e6f4f8a

File tree

3 files changed

+722
-16
lines changed

3 files changed

+722
-16
lines changed
 

‎docs/rules/prefer-expect-assertions.md

+60
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ test('my test', () => {
5858

5959
## Options
6060

61+
This rule can be configured to only check tests that match certain patterns that
62+
typically look like `expect` calls might be missed, such as in promises or
63+
loops.
64+
65+
By default, none of these options are enabled meaning the rule checks _every_
66+
test for a call to either `expect.hasAssertions` or `expect.assertions`. If any
67+
of the options are enabled the rule checks any test that matches _at least one_
68+
of the patterns represented by the enabled options (think "OR" rather than
69+
"AND").
70+
6171
#### `onlyFunctionsWithAsyncKeyword`
6272

6373
When `true`, this rule will only warn for tests that use the `async` keyword.
@@ -97,3 +107,53 @@ test('my test', async () => {
97107
expect(result).toBe('foo');
98108
});
99109
```
110+
111+
#### `onlyFunctionsWithExpectInLoop`
112+
113+
When `true`, this rule will only warn for tests that have `expect` calls within
114+
a native loop.
115+
116+
```json
117+
{
118+
"rules": {
119+
"jest/prefer-expect-assertions": [
120+
"warn",
121+
{ "onlyFunctionsWithAsyncKeyword": true }
122+
]
123+
}
124+
}
125+
```
126+
127+
Examples of **incorrect** code when `'onlyFunctionsWithExpectInLoop'` is `true`:
128+
129+
```js
130+
describe('getNumbers', () => {
131+
it('only returns numbers that are greater than zero', () => {
132+
const numbers = getNumbers();
133+
134+
for (const number in numbers) {
135+
expect(number).toBeGreaterThan(0);
136+
}
137+
});
138+
});
139+
```
140+
141+
Examples of **correct** code when `'onlyFunctionsWithExpectInLoop'` is `true`:
142+
143+
```js
144+
describe('getNumbers', () => {
145+
it('only returns numbers that are greater than zero', () => {
146+
expect.hasAssertions();
147+
148+
const numbers = getNumbers();
149+
150+
for (const number in numbers) {
151+
expect(number).toBeGreaterThan(0);
152+
}
153+
});
154+
155+
it('returns more than one number', () => {
156+
expect(getNumbers().length).toBeGreaterThan(1);
157+
});
158+
});
159+
```

‎src/rules/__tests__/prefer-expect-assertions.test.ts

+597-9
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,73 @@ ruleTester.run('prefer-expect-assertions', rule, {
2121
it("it1", function() {
2222
expect.assertions(1);
2323
expect(someValue).toBe(true)
24-
})
24+
});
2525
`,
2626
'test("it1")',
2727
'itHappensToStartWithIt("foo", function() {})',
2828
'testSomething("bar", function() {})',
2929
'it(async () => {expect.assertions(0);})',
30+
dedent`
31+
it("returns numbers that are greater than four", function() {
32+
expect.assertions(2);
33+
34+
for(let thing in things) {
35+
expect(number).toBeGreaterThan(4);
36+
}
37+
});
38+
`,
39+
dedent`
40+
it("returns numbers that are greater than four", function() {
41+
expect.hasAssertions();
42+
43+
for (let i = 0; i < things.length; i++) {
44+
expect(number).toBeGreaterThan(4);
45+
}
46+
});
47+
`,
3048
{
3149
code: dedent`
3250
it("it1", async () => {
3351
expect.assertions(1);
3452
expect(someValue).toBe(true)
35-
})
53+
});
3654
`,
3755
options: [{ onlyFunctionsWithAsyncKeyword: true }],
3856
},
3957
{
4058
code: dedent`
4159
it("it1", function() {
4260
expect(someValue).toBe(true)
43-
})
61+
});
4462
`,
4563
options: [{ onlyFunctionsWithAsyncKeyword: true }],
4664
},
4765
{
4866
code: 'it("it1", () => {})',
4967
options: [{ onlyFunctionsWithAsyncKeyword: true }],
5068
},
69+
{
70+
code: dedent`
71+
it("returns numbers that are greater than four", async () => {
72+
expect.assertions(2);
73+
74+
for(let thing in things) {
75+
expect(number).toBeGreaterThan(4);
76+
}
77+
});
78+
`,
79+
options: [{ onlyFunctionsWithAsyncKeyword: true }],
80+
},
81+
{
82+
code: dedent`
83+
it("returns numbers that are greater than four", () => {
84+
for(let thing in things) {
85+
expect(number).toBeGreaterThan(4);
86+
}
87+
});
88+
`,
89+
options: [{ onlyFunctionsWithAsyncKeyword: true }],
90+
},
5191
],
5292
invalid: [
5393
{
@@ -95,7 +135,7 @@ ruleTester.run('prefer-expect-assertions', rule, {
95135
it("it1", function() {
96136
someFunctionToDo();
97137
someFunctionToDo2();
98-
})
138+
});
99139
`,
100140
errors: [
101141
{
@@ -109,7 +149,7 @@ ruleTester.run('prefer-expect-assertions', rule, {
109149
it("it1", function() {
110150
expect.hasAssertions();someFunctionToDo();
111151
someFunctionToDo2();
112-
})
152+
});
113153
`,
114154
},
115155
{
@@ -118,7 +158,7 @@ ruleTester.run('prefer-expect-assertions', rule, {
118158
it("it1", function() {
119159
expect.assertions();someFunctionToDo();
120160
someFunctionToDo2();
121-
})
161+
});
122162
`,
123163
},
124164
],
@@ -223,7 +263,7 @@ ruleTester.run('prefer-expect-assertions', rule, {
223263
someFunctionToDo();
224264
someFunctionToDo2();
225265
});
226-
})
266+
});
227267
`,
228268
errors: [
229269
{
@@ -236,7 +276,7 @@ ruleTester.run('prefer-expect-assertions', rule, {
236276
output: dedent`
237277
it("it1", function() {
238278
expect.hasAssertions();
239-
})
279+
});
240280
`,
241281
},
242282
],
@@ -247,7 +287,64 @@ ruleTester.run('prefer-expect-assertions', rule, {
247287
code: dedent`
248288
it("it1", async function() {
249289
expect(someValue).toBe(true);
250-
})
290+
});
291+
`,
292+
options: [{ onlyFunctionsWithAsyncKeyword: true }],
293+
errors: [
294+
{
295+
messageId: 'haveExpectAssertions',
296+
column: 1,
297+
line: 1,
298+
},
299+
],
300+
},
301+
{
302+
code: dedent`
303+
it("returns numbers that are greater than four", async () => {
304+
for(let thing in things) {
305+
expect(number).toBeGreaterThan(4);
306+
}
307+
});
308+
`,
309+
options: [{ onlyFunctionsWithAsyncKeyword: true }],
310+
errors: [
311+
{
312+
messageId: 'haveExpectAssertions',
313+
column: 1,
314+
line: 1,
315+
},
316+
],
317+
},
318+
{
319+
code: dedent`
320+
it("returns numbers that are greater than four", async () => {
321+
for (const number of getNumbers()) {
322+
expect(number).toBeGreaterThan(4);
323+
}
324+
});
325+
`,
326+
options: [{ onlyFunctionsWithAsyncKeyword: true }],
327+
errors: [
328+
{
329+
messageId: 'haveExpectAssertions',
330+
column: 1,
331+
line: 1,
332+
},
333+
],
334+
},
335+
{
336+
code: dedent`
337+
it("returns numbers that are greater than four", async () => {
338+
for (const number of getNumbers()) {
339+
expect(number).toBeGreaterThan(4);
340+
}
341+
});
342+
343+
it("returns numbers that are greater than five", () => {
344+
for (const number of getNumbers()) {
345+
expect(number).toBeGreaterThan(5);
346+
}
347+
});
251348
`,
252349
options: [{ onlyFunctionsWithAsyncKeyword: true }],
253350
errors: [
@@ -261,6 +358,497 @@ ruleTester.run('prefer-expect-assertions', rule, {
261358
],
262359
});
263360

361+
ruleTester.run('prefer-expect-assertions (loops)', rule, {
362+
valid: [
363+
{
364+
code: dedent`
365+
const expectNumbersToBeGreaterThan = (numbers, value) => {
366+
for (let number of numbers) {
367+
expect(number).toBeGreaterThan(value);
368+
}
369+
};
370+
371+
it('returns numbers that are greater than two', function () {
372+
expectNumbersToBeGreaterThan(getNumbers(), 2);
373+
});
374+
`,
375+
options: [{ onlyFunctionsWithExpectInLoop: true }],
376+
},
377+
{
378+
code: dedent`
379+
it("returns numbers that are greater than five", function () {
380+
expect.assertions(2);
381+
382+
for (const number of getNumbers()) {
383+
expect(number).toBeGreaterThan(5);
384+
}
385+
});
386+
`,
387+
options: [{ onlyFunctionsWithExpectInLoop: true }],
388+
},
389+
{
390+
code: dedent`
391+
it("returns things that are less than ten", function () {
392+
expect.hasAssertions();
393+
394+
for (const thing in things) {
395+
expect(thing).toBeLessThan(10);
396+
}
397+
});
398+
`,
399+
options: [{ onlyFunctionsWithExpectInLoop: true }],
400+
},
401+
],
402+
invalid: [
403+
{
404+
code: dedent`
405+
it('only returns numbers that are greater than six', () => {
406+
for (const number of getNumbers()) {
407+
expect(number).toBeGreaterThan(6);
408+
}
409+
});
410+
`,
411+
options: [{ onlyFunctionsWithExpectInLoop: true }],
412+
errors: [
413+
{
414+
messageId: 'haveExpectAssertions',
415+
column: 1,
416+
line: 1,
417+
},
418+
],
419+
},
420+
{
421+
code: dedent`
422+
it('returns numbers that are greater than two', function () {
423+
const expectNumbersToBeGreaterThan = (numbers, value) => {
424+
for (let number of numbers) {
425+
expect(number).toBeGreaterThan(value);
426+
}
427+
};
428+
429+
expectNumbersToBeGreaterThan(getNumbers(), 2);
430+
});
431+
`,
432+
options: [{ onlyFunctionsWithExpectInLoop: true }],
433+
errors: [
434+
{
435+
messageId: 'haveExpectAssertions',
436+
column: 1,
437+
line: 1,
438+
},
439+
],
440+
},
441+
{
442+
code: dedent`
443+
it("only returns numbers that are greater than seven", function () {
444+
const numbers = getNumbers();
445+
446+
for (let i = 0; i < numbers.length; i++) {
447+
expect(numbers[i]).toBeGreaterThan(7);
448+
}
449+
});
450+
`,
451+
options: [{ onlyFunctionsWithExpectInLoop: true }],
452+
errors: [
453+
{
454+
messageId: 'haveExpectAssertions',
455+
column: 1,
456+
line: 1,
457+
},
458+
],
459+
},
460+
{
461+
code: dedent`
462+
it('has the number two', () => {
463+
expect(number).toBe(2);
464+
});
465+
466+
it('only returns numbers that are less than twenty', () => {
467+
for (const number of getNumbers()) {
468+
expect(number).toBeLessThan(20);
469+
}
470+
});
471+
`,
472+
options: [{ onlyFunctionsWithExpectInLoop: true }],
473+
errors: [
474+
{
475+
messageId: 'haveExpectAssertions',
476+
column: 1,
477+
line: 5,
478+
},
479+
],
480+
},
481+
{
482+
code: dedent`
483+
it("is wrong");
484+
485+
it("is a test", () => {
486+
for (const number of getNumbers()) {
487+
expect(number).toBeGreaterThan(4);
488+
}
489+
});
490+
`,
491+
options: [{ onlyFunctionsWithExpectInLoop: true }],
492+
errors: [
493+
{
494+
messageId: 'haveExpectAssertions',
495+
column: 1,
496+
line: 3,
497+
},
498+
],
499+
},
500+
{
501+
code: dedent`
502+
it("is a number that is greater than four", () => {
503+
expect(number).toBeGreaterThan(4);
504+
});
505+
506+
it("returns numbers that are greater than four", () => {
507+
for (const number of getNumbers()) {
508+
expect(number).toBeGreaterThan(4);
509+
}
510+
});
511+
512+
it("returns numbers that are greater than five", () => {
513+
expect(number).toBeGreaterThan(5);
514+
});
515+
`,
516+
options: [{ onlyFunctionsWithExpectInLoop: true }],
517+
errors: [
518+
{
519+
messageId: 'haveExpectAssertions',
520+
column: 1,
521+
line: 5,
522+
},
523+
],
524+
},
525+
{
526+
code: dedent`
527+
it.each([1, 2, 3])("returns numbers that are greater than four", () => {
528+
for (const number of getNumbers()) {
529+
expect(number).toBeGreaterThan(4);
530+
}
531+
});
532+
533+
it("is a number that is greater than four", () => {
534+
expect(number).toBeGreaterThan(4);
535+
});
536+
`,
537+
options: [{ onlyFunctionsWithExpectInLoop: true }],
538+
errors: [
539+
{
540+
messageId: 'haveExpectAssertions',
541+
column: 1,
542+
line: 1,
543+
},
544+
],
545+
},
546+
{
547+
code: dedent`
548+
it("returns numbers that are greater than four", () => {
549+
for (const number of getNumbers()) {
550+
expect(number).toBeGreaterThan(4);
551+
}
552+
});
553+
554+
it("is a number that is greater than four", () => {
555+
expect(number).toBeGreaterThan(4);
556+
});
557+
`,
558+
options: [{ onlyFunctionsWithExpectInLoop: true }],
559+
errors: [
560+
{
561+
messageId: 'haveExpectAssertions',
562+
column: 1,
563+
line: 1,
564+
},
565+
],
566+
},
567+
{
568+
code: dedent`
569+
it("returns numbers that are greater than four", () => {
570+
for (const number of getNumbers()) {
571+
expect(number).toBeGreaterThan(4);
572+
}
573+
});
574+
575+
it("is a number that is greater than four", () => {
576+
expect.hasAssertions();
577+
578+
expect(number).toBeGreaterThan(4);
579+
});
580+
`,
581+
options: [{ onlyFunctionsWithExpectInLoop: true }],
582+
errors: [
583+
{
584+
messageId: 'haveExpectAssertions',
585+
column: 1,
586+
line: 1,
587+
},
588+
],
589+
},
590+
{
591+
code: dedent`
592+
it("it1", () => {
593+
expect.hasAssertions();
594+
595+
for (const number of getNumbers()) {
596+
expect(number).toBeGreaterThan(0);
597+
}
598+
});
599+
600+
it("it1", () => {
601+
for (const number of getNumbers()) {
602+
expect(number).toBeGreaterThan(0);
603+
}
604+
});
605+
`,
606+
options: [{ onlyFunctionsWithExpectInLoop: true }],
607+
errors: [
608+
{
609+
messageId: 'haveExpectAssertions',
610+
column: 1,
611+
line: 9,
612+
},
613+
],
614+
},
615+
{
616+
code: dedent`
617+
it("returns numbers that are greater than four", async () => {
618+
for (const number of await getNumbers()) {
619+
expect(number).toBeGreaterThan(4);
620+
}
621+
});
622+
623+
it("returns numbers that are greater than five", () => {
624+
for (const number of getNumbers()) {
625+
expect(number).toBeGreaterThan(5);
626+
}
627+
});
628+
`,
629+
options: [{ onlyFunctionsWithExpectInLoop: true }],
630+
errors: [
631+
{
632+
messageId: 'haveExpectAssertions',
633+
column: 1,
634+
line: 1,
635+
},
636+
{
637+
messageId: 'haveExpectAssertions',
638+
column: 1,
639+
line: 7,
640+
},
641+
],
642+
},
643+
{
644+
code: dedent`
645+
it("it1", async () => {
646+
expect.hasAssertions();
647+
648+
for (const number of getNumbers()) {
649+
expect(number).toBeGreaterThan(4);
650+
}
651+
});
652+
653+
it("it1", () => {
654+
for (const number of getNumbers()) {
655+
expect(number).toBeGreaterThan(4);
656+
}
657+
});
658+
`,
659+
options: [{ onlyFunctionsWithExpectInLoop: true }],
660+
errors: [
661+
{
662+
messageId: 'haveExpectAssertions',
663+
column: 1,
664+
line: 9,
665+
},
666+
],
667+
},
668+
{
669+
code: dedent`
670+
it.skip.each\`\`("it1", async () => {
671+
expect.hasAssertions();
672+
673+
for (const number of getNumbers()) {
674+
expect(number).toBeGreaterThan(4);
675+
}
676+
});
677+
678+
it("it1", () => {
679+
for (const number of getNumbers()) {
680+
expect(number).toBeGreaterThan(4);
681+
}
682+
});
683+
`,
684+
options: [{ onlyFunctionsWithExpectInLoop: true }],
685+
errors: [
686+
{
687+
messageId: 'haveExpectAssertions',
688+
column: 1,
689+
line: 9,
690+
},
691+
],
692+
},
693+
{
694+
code: dedent`
695+
it("it1", async () => {
696+
for (const number of getNumbers()) {
697+
expect(number).toBeGreaterThan(4);
698+
}
699+
});
700+
701+
it("it1", () => {
702+
expect.hasAssertions();
703+
704+
for (const number of getNumbers()) {
705+
expect(number).toBeGreaterThan(4);
706+
}
707+
});
708+
`,
709+
options: [{ onlyFunctionsWithExpectInLoop: true }],
710+
errors: [
711+
{
712+
messageId: 'haveExpectAssertions',
713+
column: 1,
714+
line: 1,
715+
},
716+
],
717+
},
718+
],
719+
});
720+
721+
ruleTester.run('prefer-expect-assertions (mixed)', rule, {
722+
valid: [
723+
{
724+
code: dedent`
725+
it('only returns numbers that are greater than zero', async () => {
726+
expect.hasAssertions();
727+
728+
for (const number of await getNumbers()) {
729+
expect(number).toBeGreaterThan(0);
730+
}
731+
});
732+
`,
733+
options: [
734+
{
735+
onlyFunctionsWithAsyncKeyword: true,
736+
onlyFunctionsWithExpectInLoop: true,
737+
},
738+
],
739+
},
740+
{
741+
code: dedent`
742+
it('only returns numbers that are greater than zero', async () => {
743+
expect.assertions(2);
744+
745+
for (const number of await getNumbers()) {
746+
expect(number).toBeGreaterThan(0);
747+
}
748+
});
749+
`,
750+
options: [
751+
{
752+
onlyFunctionsWithAsyncKeyword: true,
753+
onlyFunctionsWithExpectInLoop: true,
754+
},
755+
],
756+
},
757+
],
758+
invalid: [
759+
{
760+
code: dedent`
761+
it('only returns numbers that are greater than zero', () => {
762+
for (const number of getNumbers()) {
763+
expect(number).toBeGreaterThan(0);
764+
}
765+
});
766+
767+
it("is zero", () => {
768+
expect.hasAssertions();
769+
770+
expect(0).toBe(0);
771+
});
772+
`,
773+
options: [{ onlyFunctionsWithExpectInLoop: true }],
774+
errors: [
775+
{
776+
messageId: 'haveExpectAssertions',
777+
column: 1,
778+
line: 1,
779+
},
780+
],
781+
},
782+
{
783+
code: dedent`
784+
it('only returns numbers that are greater than zero', () => {
785+
expect.hasAssertions();
786+
787+
for (const number of getNumbers()) {
788+
expect(number).toBeGreaterThan(0);
789+
}
790+
});
791+
792+
it('only returns numbers that are less than 100', () => {
793+
for (const number of getNumbers()) {
794+
expect(number).toBeLessThan(0);
795+
}
796+
});
797+
`,
798+
options: [{ onlyFunctionsWithExpectInLoop: true }],
799+
errors: [
800+
{
801+
messageId: 'haveExpectAssertions',
802+
column: 1,
803+
line: 9,
804+
},
805+
],
806+
},
807+
{
808+
code: dedent`
809+
it("to be true", async function() {
810+
expect(someValue).toBe(true);
811+
});
812+
`,
813+
options: [
814+
{
815+
onlyFunctionsWithAsyncKeyword: true,
816+
onlyFunctionsWithExpectInLoop: true,
817+
},
818+
],
819+
errors: [
820+
{
821+
messageId: 'haveExpectAssertions',
822+
column: 1,
823+
line: 1,
824+
},
825+
],
826+
},
827+
{
828+
code: dedent`
829+
it('only returns numbers that are greater than zero', async () => {
830+
for (const number of getNumbers()) {
831+
expect(number).toBeGreaterThan(0);
832+
}
833+
});
834+
`,
835+
options: [
836+
{
837+
onlyFunctionsWithAsyncKeyword: true,
838+
onlyFunctionsWithExpectInLoop: true,
839+
},
840+
],
841+
errors: [
842+
{
843+
messageId: 'haveExpectAssertions',
844+
column: 1,
845+
line: 1,
846+
},
847+
],
848+
},
849+
],
850+
});
851+
264852
ruleTester.run('.each support', rule, {
265853
valid: [
266854
'test.each()("is fine", () => { expect.assertions(0); })',

‎src/rules/prefer-expect-assertions.ts

+65-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createRule,
99
getAccessorValue,
1010
hasOnlyOneArgument,
11+
isExpectCall,
1112
isFunction,
1213
isSupportedAccessor,
1314
isTestCaseCall,
@@ -44,6 +45,7 @@ const suggestRemovingExtraArguments = (
4445

4546
interface RuleOptions {
4647
onlyFunctionsWithAsyncKeyword?: boolean;
48+
onlyFunctionsWithExpectInLoop?: boolean;
4749
}
4850

4951
type MessageIds =
@@ -89,18 +91,69 @@ export default createRule<[RuleOptions], MessageIds>({
8991
{
9092
type: 'object',
9193
properties: {
92-
onlyFunctionsWithAsyncKeyword: {
93-
type: 'boolean',
94-
},
94+
onlyFunctionsWithAsyncKeyword: { type: 'boolean' },
95+
onlyFunctionsWithExpectInLoop: { type: 'boolean' },
9596
},
9697
additionalProperties: false,
9798
},
9899
],
99100
},
100-
defaultOptions: [{ onlyFunctionsWithAsyncKeyword: false }],
101+
defaultOptions: [
102+
{
103+
onlyFunctionsWithAsyncKeyword: false,
104+
onlyFunctionsWithExpectInLoop: false,
105+
},
106+
],
101107
create(context, [options]) {
108+
let hasExpectInLoop = false;
109+
let inTestCaseCall = false;
110+
let inForLoop = false;
111+
112+
const shouldCheckFunction = (testFunction: TSESTree.FunctionLike) => {
113+
if (
114+
!options.onlyFunctionsWithAsyncKeyword &&
115+
!options.onlyFunctionsWithExpectInLoop
116+
) {
117+
return true;
118+
}
119+
120+
if (options.onlyFunctionsWithAsyncKeyword) {
121+
if (testFunction.async) {
122+
return true;
123+
}
124+
}
125+
126+
if (options.onlyFunctionsWithExpectInLoop) {
127+
if (hasExpectInLoop) {
128+
return true;
129+
}
130+
}
131+
132+
return false;
133+
};
134+
135+
const enterForLoop = () => (inForLoop = true);
136+
const exitForLoop = () => (inForLoop = false);
137+
102138
return {
103-
CallExpression(node: TSESTree.CallExpression) {
139+
ForStatement: enterForLoop,
140+
'ForStatement:exit': exitForLoop,
141+
ForInStatement: enterForLoop,
142+
'ForInStatement:exit': exitForLoop,
143+
ForOfStatement: enterForLoop,
144+
'ForOfStatement:exit': exitForLoop,
145+
CallExpression(node) {
146+
if (isTestCaseCall(node)) {
147+
inTestCaseCall = true;
148+
149+
return;
150+
}
151+
152+
if (isExpectCall(node) && inTestCaseCall && inForLoop) {
153+
hasExpectInLoop = true;
154+
}
155+
},
156+
'CallExpression:exit'(node: TSESTree.CallExpression) {
104157
if (!isTestCaseCall(node)) {
105158
return;
106159
}
@@ -113,12 +166,17 @@ export default createRule<[RuleOptions], MessageIds>({
113166

114167
if (
115168
!isFunction(testFn) ||
116-
testFn.body.type !== AST_NODE_TYPES.BlockStatement ||
117-
(options.onlyFunctionsWithAsyncKeyword && !testFn.async)
169+
testFn.body.type !== AST_NODE_TYPES.BlockStatement
118170
) {
119171
return;
120172
}
121173

174+
if (!shouldCheckFunction(testFn)) {
175+
return;
176+
}
177+
178+
hasExpectInLoop = false;
179+
122180
const testFuncBody = testFn.body.body;
123181

124182
if (!isFirstLineExprStmt(testFuncBody)) {

0 commit comments

Comments
 (0)
Please sign in to comment.