@@ -42,6 +42,35 @@ ruleTester.run('valid-expect', rule, {
4242 'test("valid-expect", async () => { await Promise.race([expect(Promise.reject(2)).not.rejects.toBeDefined(), expect(Promise.reject(2)).rejects.not.toBeDefined()]); });' ,
4343 'test("valid-expect", async () => { await Promise.allSettled([expect(Promise.reject(2)).not.rejects.toBeDefined(), expect(Promise.reject(2)).rejects.not.toBeDefined()]); });' ,
4444 'test("valid-expect", async () => { await Promise.any([expect(Promise.reject(2)).not.rejects.toBeDefined(), expect(Promise.reject(2)).rejects.not.toBeDefined()]); });' ,
45+ 'test("valid-expect", async () => { return expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => console.log("valid-case")); });' ,
46+ 'test("valid-expect", async () => { return expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => console.log("valid-case")).then(() => console.log("another valid case")); });' ,
47+ 'test("valid-expect", async () => { return expect(Promise.reject(2)).not.resolves.toBeDefined().catch(() => console.log("valid-case")); });' ,
48+ 'test("valid-expect", async () => { return expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => console.log("valid-case")).catch(() => console.log("another valid case")); });' ,
49+ 'test("valid-expect", async () => { return expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => { expect(someMock).toHaveBeenCalledTimes(1); }); });' ,
50+ 'test("valid-expect", async () => { await expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => console.log("valid-case")); });' ,
51+ 'test("valid-expect", async () => { await expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => console.log("valid-case")).then(() => console.log("another valid case")); });' ,
52+ 'test("valid-expect", async () => { await expect(Promise.reject(2)).not.resolves.toBeDefined().catch(() => console.log("valid-case")); });' ,
53+ 'test("valid-expect", async () => { await expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => console.log("valid-case")).catch(() => console.log("another valid case")); });' ,
54+ 'test("valid-expect", async () => { await expect(Promise.reject(2)).not.resolves.toBeDefined().then(() => { expect(someMock).toHaveBeenCalledTimes(1); }); });' ,
55+ {
56+ code : `test("valid-expect", () => {
57+ return expect(functionReturningAPromise()).resolves.toEqual(1).then(() => {
58+ return expect(Promise.resolve(2)).resolves.toBe(1);
59+ });
60+ });` ,
61+ } ,
62+ {
63+ code : `test("valid-expect", () => {
64+ return expect(functionReturningAPromise()).resolves.toEqual(1).then(async () => {
65+ await expect(Promise.resolve(2)).resolves.toBe(1);
66+ });
67+ });` ,
68+ } ,
69+ {
70+ code : `test("valid-expect", () => {
71+ return expect(functionReturningAPromise()).resolves.toEqual(1).then(() => expect(Promise.resolve(2)).resolves.toBe(1));
72+ });` ,
73+ } ,
4574 ] ,
4675
4776 invalid : [
@@ -484,5 +513,40 @@ ruleTester.run('valid-expect', rule, {
484513 } ,
485514 ] ,
486515 } ,
516+ {
517+ code : `test("valid-expect", () => {
518+ return expect(functionReturningAPromise()).resolves.toEqual(1).then(() => {
519+ expect(Promise.resolve(2)).resolves.toBe(1);
520+ });
521+ });` ,
522+ errors : [
523+ {
524+ line : 3 ,
525+ column : 11 ,
526+ endLine : 3 ,
527+ endColumn : 54 ,
528+ messageId : 'asyncMustBeAwaited' ,
529+ data : { orReturned : ' or returned' } ,
530+ } ,
531+ ] ,
532+ } ,
533+ {
534+ code : `test("valid-expect", () => {
535+ return expect(functionReturningAPromise()).resolves.toEqual(1).then(async () => {
536+ await expect(Promise.resolve(2)).resolves.toBe(1);
537+ expect(Promise.resolve(4)).resolves.toBe(4);
538+ });
539+ });` ,
540+ errors : [
541+ {
542+ line : 4 ,
543+ column : 11 ,
544+ endLine : 4 ,
545+ endColumn : 54 ,
546+ messageId : 'asyncMustBeAwaited' ,
547+ data : { orReturned : ' or returned' } ,
548+ } ,
549+ ] ,
550+ } ,
487551 ] ,
488552} ) ;
0 commit comments