Skip to content

Commit 004f14e

Browse files
committed
Revert "fix: valid-expect test"
This reverts commit e652a25.
1 parent e652a25 commit 004f14e

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/rules/__tests__/valid-expect.test.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ ruleTester.run('valid-expect', rule, {
431431
async toResolve(obj) {
432432
this.isNot
433433
? expect(obj).toBe(true)
434-
: expect(obj).resolves.not.toThrow();
434+
: await expect(obj).resolves.not.toThrow();
435435
}
436436
});
437437
`,
@@ -457,7 +457,7 @@ ruleTester.run('valid-expect', rule, {
457457
expect.extend({
458458
async toResolve(obj) {
459459
this.isNot
460-
? expect(obj).resolves.not.toThrow()
460+
? await expect(obj).resolves.not.toThrow()
461461
: expect(obj).toBe(true);
462462
}
463463
});
@@ -488,7 +488,7 @@ ruleTester.run('valid-expect', rule, {
488488
this.isNot
489489
? expect(obj).toBe(true)
490490
: anotherCondition
491-
? expect(obj).resolves.not.toThrow()
491+
? await expect(obj).resolves.not.toThrow()
492492
: expect(obj).toBe(false)
493493
}
494494
});
@@ -506,7 +506,7 @@ ruleTester.run('valid-expect', rule, {
506506
{
507507
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).resolves.toBeDefined(); });',
508508
output:
509-
'test("valid-expect", async () => { expect(Promise.resolve(2)).resolves.toBeDefined(); });',
509+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).resolves.toBeDefined(); });',
510510
errors: [
511511
{
512512
column: 30,
@@ -519,7 +519,7 @@ ruleTester.run('valid-expect', rule, {
519519
{
520520
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).toResolve(); });',
521521
output:
522-
'test("valid-expect", async () => { expect(Promise.resolve(2)).toResolve(); });',
522+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).toResolve(); });',
523523
errors: [
524524
{
525525
messageId: 'asyncMustBeAwaited',
@@ -532,7 +532,7 @@ ruleTester.run('valid-expect', rule, {
532532
{
533533
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).toResolve(); });',
534534
output:
535-
'test("valid-expect", async () => { expect(Promise.resolve(2)).toResolve(); });',
535+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).toResolve(); });',
536536
options: [{ asyncMatchers: undefined }],
537537
errors: [
538538
{
@@ -546,7 +546,7 @@ ruleTester.run('valid-expect', rule, {
546546
{
547547
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).toReject(); });',
548548
output:
549-
'test("valid-expect", async () => { expect(Promise.resolve(2)).toReject(); });',
549+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).toReject(); });',
550550
errors: [
551551
{
552552
messageId: 'asyncMustBeAwaited',
@@ -559,7 +559,7 @@ ruleTester.run('valid-expect', rule, {
559559
{
560560
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).not.toReject(); });',
561561
output:
562-
'test("valid-expect", async () => { expect(Promise.resolve(2)).not.toReject(); });',
562+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).not.toReject(); });',
563563
errors: [
564564
{
565565
messageId: 'asyncMustBeAwaited',
@@ -573,7 +573,7 @@ ruleTester.run('valid-expect', rule, {
573573
{
574574
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).resolves.not.toBeDefined(); });',
575575
output:
576-
'test("valid-expect", async () => { expect(Promise.resolve(2)).resolves.not.toBeDefined(); });',
576+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).resolves.not.toBeDefined(); });',
577577
errors: [
578578
{
579579
column: 30,
@@ -587,7 +587,7 @@ ruleTester.run('valid-expect', rule, {
587587
{
588588
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).rejects.toBeDefined(); });',
589589
output:
590-
'test("valid-expect", async () => { expect(Promise.resolve(2)).rejects.toBeDefined(); });',
590+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).rejects.toBeDefined(); });',
591591
errors: [
592592
{
593593
column: 30,
@@ -601,7 +601,7 @@ ruleTester.run('valid-expect', rule, {
601601
{
602602
code: 'test("valid-expect", () => { expect(Promise.resolve(2)).rejects.not.toBeDefined(); });',
603603
output:
604-
'test("valid-expect", async () => { expect(Promise.resolve(2)).rejects.not.toBeDefined(); });',
604+
'test("valid-expect", async () => { await expect(Promise.resolve(2)).rejects.not.toBeDefined(); });',
605605
errors: [
606606
{
607607
column: 30,
@@ -641,7 +641,7 @@ ruleTester.run('valid-expect', rule, {
641641
{
642642
code: 'test("valid-expect", () => { expect(Promise.reject(2)).toRejectWith(2); });',
643643
output:
644-
'test("valid-expect", async () => { expect(Promise.reject(2)).toRejectWith(2); });',
644+
'test("valid-expect", async () => { await expect(Promise.reject(2)).toRejectWith(2); });',
645645
options: [{ asyncMatchers: ['toRejectWith'] }],
646646
errors: [
647647
{
@@ -654,7 +654,7 @@ ruleTester.run('valid-expect', rule, {
654654
{
655655
code: 'test("valid-expect", () => { expect(Promise.reject(2)).rejects.toBe(2); });',
656656
output:
657-
'test("valid-expect", async () => { expect(Promise.reject(2)).rejects.toBe(2); });',
657+
'test("valid-expect", async () => { await expect(Promise.reject(2)).rejects.toBe(2); });',
658658
options: [{ asyncMatchers: ['toRejectWith'] }],
659659
errors: [
660660
{
@@ -834,7 +834,7 @@ ruleTester.run('valid-expect', rule, {
834834
`,
835835
output: dedent`
836836
test("valid-expect", async () => {
837-
Promise.resolve(expect(Promise.resolve(2)).resolves.not.toBeDefined());
837+
await Promise.resolve(expect(Promise.resolve(2)).resolves.not.toBeDefined());
838838
});
839839
`,
840840
errors: [
@@ -855,7 +855,7 @@ ruleTester.run('valid-expect', rule, {
855855
`,
856856
output: dedent`
857857
test("valid-expect", async () => {
858-
Promise.reject(expect(Promise.resolve(2)).resolves.not.toBeDefined());
858+
await Promise.reject(expect(Promise.resolve(2)).resolves.not.toBeDefined());
859859
});
860860
`,
861861
errors: [
@@ -897,7 +897,7 @@ ruleTester.run('valid-expect', rule, {
897897
`,
898898
output: dedent`
899899
test("valid-expect", async () => {
900-
Promise.x(expect(Promise.resolve(2)).resolves.not.toBeDefined());
900+
await Promise.x(expect(Promise.resolve(2)).resolves.not.toBeDefined());
901901
});
902902
`,
903903
errors: [
@@ -919,7 +919,7 @@ ruleTester.run('valid-expect', rule, {
919919
`,
920920
output: dedent`
921921
test("valid-expect", async () => {
922-
Promise.resolve(expect(Promise.resolve(2)).resolves.not.toBeDefined());
922+
await Promise.resolve(expect(Promise.resolve(2)).resolves.not.toBeDefined());
923923
});
924924
`,
925925
options: [{ alwaysAwait: true }],
@@ -944,7 +944,7 @@ ruleTester.run('valid-expect', rule, {
944944
`,
945945
output: dedent`
946946
test("valid-expect", async () => {
947-
Promise.all([
947+
await Promise.all([
948948
expect(Promise.resolve(2)).resolves.not.toBeDefined(),
949949
expect(Promise.resolve(3)).resolves.not.toBeDefined(),
950950
]);
@@ -973,7 +973,7 @@ ruleTester.run('valid-expect', rule, {
973973
`,
974974
output: dedent`
975975
test("valid-expect", async () => {
976-
Promise.x([
976+
await Promise.x([
977977
expect(Promise.resolve(2)).resolves.not.toBeDefined(),
978978
expect(Promise.resolve(3)).resolves.not.toBeDefined(),
979979
]);
@@ -1002,8 +1002,8 @@ ruleTester.run('valid-expect', rule, {
10021002
output: dedent`
10031003
test("valid-expect", async () => {
10041004
const assertions = [
1005-
expect(Promise.resolve(2)).resolves.not.toBeDefined(),
1006-
expect(Promise.resolve(3)).resolves.not.toBeDefined(),
1005+
await expect(Promise.resolve(2)).resolves.not.toBeDefined(),
1006+
await expect(Promise.resolve(3)).resolves.not.toBeDefined(),
10071007
]
10081008
});
10091009
`,
@@ -1070,8 +1070,8 @@ ruleTester.run('valid-expect', rule, {
10701070
output: dedent`
10711071
test("valid-expect", async () => {
10721072
const assertions = [
1073-
expect(Promise.resolve(2)).not.toResolve(),
1074-
expect(Promise.resolve(3)).resolves.toReject(),
1073+
await expect(Promise.resolve(2)).not.toResolve(),
1074+
await expect(Promise.resolve(3)).resolves.toReject(),
10751075
]
10761076
});
10771077
`,
@@ -1111,7 +1111,7 @@ ruleTester.run('valid-expect', rule, {
11111111
output: dedent`
11121112
test("valid-expect", () => {
11131113
return expect(functionReturningAPromise()).resolves.toEqual(1).then(async () => {
1114-
expect(Promise.resolve(2)).resolves.toBe(1);
1114+
await expect(Promise.resolve(2)).resolves.toBe(1);
11151115
});
11161116
});
11171117
`,

src/rules/valid-expect.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ export default createRule<[Options], MessageIds>({
380380
const targetFunction =
381381
getNormalizeFunctionExpression(functionExpression);
382382

383-
return fixer.insertTextBefore(targetFunction, 'async ');
383+
return [
384+
fixer.insertTextBefore(targetFunction, 'async '),
385+
fixer.insertTextBefore(finalNode, 'await '),
386+
];
384387
}
385388
const returnStatement =
386389
finalNode.parent.type === AST_NODE_TYPES.ReturnStatement

0 commit comments

Comments
 (0)