@@ -114,6 +114,22 @@ ruleTester.run('valid-expect', rule, {
114
114
code : 'expect(1, "1 !== 2").toBe(2);' ,
115
115
options : [ { maxArgs : 2 , minArgs : 2 } ] ,
116
116
} ,
117
+ {
118
+ code : 'test("valid-expect", () => { expect(2).not.toBe(2); });' ,
119
+ options : [ { asyncMatchers : [ 'toRejectWith' ] } ] ,
120
+ } ,
121
+ {
122
+ code : 'test("valid-expect", () => { expect(Promise.reject(2)).toRejectWith(2); });' ,
123
+ options : [ { asyncMatchers : [ 'toResolveWith' ] } ] ,
124
+ } ,
125
+ {
126
+ code : 'test("valid-expect", async () => { await expect(Promise.resolve(2)).toResolve(); });' ,
127
+ options : [ { asyncMatchers : [ 'toResolveWith' ] } ] ,
128
+ } ,
129
+ {
130
+ code : 'test("valid-expect", async () => { expect(Promise.resolve(2)).toResolve(); });' ,
131
+ options : [ { asyncMatchers : [ 'toResolveWith' ] } ] ,
132
+ } ,
117
133
] ,
118
134
invalid : [
119
135
/*
@@ -466,6 +482,51 @@ ruleTester.run('valid-expect', rule, {
466
482
} ,
467
483
] ,
468
484
} ,
485
+ {
486
+ code : 'test("valid-expect", () => { expect(Promise.resolve(2)).toResolve(); });' ,
487
+ errors : [
488
+ {
489
+ messageId : 'asyncMustBeAwaited' ,
490
+ data : { orReturned : ' or returned' } ,
491
+ column : 30 ,
492
+ line : 1 ,
493
+ } ,
494
+ ] ,
495
+ } ,
496
+ {
497
+ code : 'test("valid-expect", () => { expect(Promise.resolve(2)).toResolve(); });' ,
498
+ options : [ { asyncMatchers : undefined } ] ,
499
+ errors : [
500
+ {
501
+ messageId : 'asyncMustBeAwaited' ,
502
+ data : { orReturned : ' or returned' } ,
503
+ column : 30 ,
504
+ line : 1 ,
505
+ } ,
506
+ ] ,
507
+ } ,
508
+ {
509
+ code : 'test("valid-expect", () => { expect(Promise.resolve(2)).toReject(); });' ,
510
+ errors : [
511
+ {
512
+ messageId : 'asyncMustBeAwaited' ,
513
+ data : { orReturned : ' or returned' } ,
514
+ column : 30 ,
515
+ line : 1 ,
516
+ } ,
517
+ ] ,
518
+ } ,
519
+ {
520
+ code : 'test("valid-expect", () => { expect(Promise.resolve(2)).not.toReject(); });' ,
521
+ errors : [
522
+ {
523
+ messageId : 'asyncMustBeAwaited' ,
524
+ data : { orReturned : ' or returned' } ,
525
+ column : 30 ,
526
+ line : 1 ,
527
+ } ,
528
+ ] ,
529
+ } ,
469
530
// expect().resolves.not
470
531
{
471
532
code : 'test("valid-expect", () => { expect(Promise.resolve(2)).resolves.not.toBeDefined(); });' ,
@@ -525,6 +586,28 @@ ruleTester.run('valid-expect', rule, {
525
586
} ,
526
587
] ,
527
588
} ,
589
+ {
590
+ code : 'test("valid-expect", () => { expect(Promise.reject(2)).toRejectWith(2); });' ,
591
+ options : [ { asyncMatchers : [ 'toRejectWith' ] } ] ,
592
+ errors : [
593
+ {
594
+ messageId : 'asyncMustBeAwaited' ,
595
+ data : { orReturned : ' or returned' } ,
596
+ column : 30 ,
597
+ } ,
598
+ ] ,
599
+ } ,
600
+ {
601
+ code : 'test("valid-expect", () => { expect(Promise.reject(2)).rejects.toBe(2); });' ,
602
+ options : [ { asyncMatchers : [ 'toRejectWith' ] } ] ,
603
+ errors : [
604
+ {
605
+ messageId : 'asyncMustBeAwaited' ,
606
+ data : { orReturned : ' or returned' } ,
607
+ column : 30 ,
608
+ } ,
609
+ ] ,
610
+ } ,
528
611
// alwaysAwait:false, one not awaited
529
612
{
530
613
code : dedent `
@@ -631,6 +714,22 @@ ruleTester.run('valid-expect', rule, {
631
714
} ,
632
715
] ,
633
716
} ,
717
+ {
718
+ code : dedent `
719
+ test("valid-expect", async () => {
720
+ await expect(Promise.resolve(2)).toResolve();
721
+ return expect(Promise.resolve(1)).toReject();
722
+ });
723
+ ` ,
724
+ options : [ { alwaysAwait : true } ] ,
725
+ errors : [
726
+ {
727
+ messageId : 'asyncMustBeAwaited' ,
728
+ column : 10 ,
729
+ line : 3 ,
730
+ } ,
731
+ ] ,
732
+ } ,
634
733
635
734
/**
636
735
* Promise.x(expect()) usages
@@ -771,6 +870,54 @@ ruleTester.run('valid-expect', rule, {
771
870
} ,
772
871
] ,
773
872
} ,
873
+ {
874
+ code : dedent `
875
+ test("valid-expect", () => {
876
+ const assertions = [
877
+ expect(Promise.resolve(2)).toResolve(),
878
+ expect(Promise.resolve(3)).toReject(),
879
+ ]
880
+ });
881
+ ` ,
882
+ errors : [
883
+ {
884
+ messageId : 'asyncMustBeAwaited' ,
885
+ data : { orReturned : ' or returned' } ,
886
+ column : 5 ,
887
+ line : 3 ,
888
+ } ,
889
+ {
890
+ messageId : 'asyncMustBeAwaited' ,
891
+ data : { orReturned : ' or returned' } ,
892
+ column : 5 ,
893
+ line : 4 ,
894
+ } ,
895
+ ] ,
896
+ } ,
897
+ {
898
+ code : dedent `
899
+ test("valid-expect", () => {
900
+ const assertions = [
901
+ expect(Promise.resolve(2)).not.toResolve(),
902
+ expect(Promise.resolve(3)).resolves.toReject(),
903
+ ]
904
+ });
905
+ ` ,
906
+ errors : [
907
+ {
908
+ messageId : 'asyncMustBeAwaited' ,
909
+ data : { orReturned : ' or returned' } ,
910
+ column : 5 ,
911
+ line : 3 ,
912
+ } ,
913
+ {
914
+ messageId : 'asyncMustBeAwaited' ,
915
+ data : { orReturned : ' or returned' } ,
916
+ column : 5 ,
917
+ line : 4 ,
918
+ } ,
919
+ ] ,
920
+ } ,
774
921
// Code coverage for line 29
775
922
{
776
923
code : 'expect(Promise.resolve(2)).resolves.toBe;' ,
0 commit comments