Skip to content

Commit

Permalink
fix: valid-expect logic
Browse files Browse the repository at this point in the history
  • Loading branch information
y-hsgw committed May 12, 2024
1 parent 58c4046 commit ae8ecac
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 19 deletions.
168 changes: 166 additions & 2 deletions src/rules/__tests__/valid-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
column: 12,
endColumn: 4,
messageId: 'asyncMustBeAwaited',
},
{
column: 9,
endColumn: 43,
Expand Down Expand Up @@ -463,6 +468,11 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
column: 12,
endColumn: 4,
messageId: 'asyncMustBeAwaited',
},
{
column: 9,
endColumn: 43,
Expand Down Expand Up @@ -494,6 +504,11 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
column: 12,
endColumn: 4,
messageId: 'asyncMustBeAwaited',
},
{
column: 9,
endColumn: 43,
Expand All @@ -508,6 +523,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).resolves.toBeDefined(); });',
errors: [
{
column: 22,
endColumn: 82,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
column: 30,
endColumn: 79,
Expand All @@ -521,6 +542,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).toResolve(); });',
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand All @@ -535,6 +562,12 @@ ruleTester.run('valid-expect', rule, {
'test("valid-expect", async () => { await expect(Promise.resolve(2)).toResolve(); });',
options: [{ asyncMatchers: undefined }],
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand All @@ -548,6 +581,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).toReject(); });',
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand All @@ -561,6 +600,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).not.toReject(); });',
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand All @@ -575,6 +620,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).resolves.not.toBeDefined(); });',
errors: [
{
column: 22,
endColumn: 86,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
column: 30,
endColumn: 83,
Expand All @@ -589,6 +640,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).rejects.toBeDefined(); });',
errors: [
{
column: 22,
endColumn: 81,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
column: 30,
endColumn: 78,
Expand All @@ -603,6 +660,12 @@ ruleTester.run('valid-expect', rule, {
output:
'test("valid-expect", async () => { await expect(Promise.resolve(2)).rejects.not.toBeDefined(); });',
errors: [
{
column: 22,
endColumn: 85,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
column: 30,
endColumn: 82,
Expand Down Expand Up @@ -644,6 +707,11 @@ ruleTester.run('valid-expect', rule, {
'test("valid-expect", async () => { await expect(Promise.reject(2)).toRejectWith(2); });',
options: [{ asyncMatchers: ['toRejectWith'] }],
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand All @@ -657,6 +725,11 @@ ruleTester.run('valid-expect', rule, {
'test("valid-expect", async () => { await expect(Promise.reject(2)).rejects.toBe(2); });',
options: [{ asyncMatchers: ['toRejectWith'] }],
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand Down Expand Up @@ -838,6 +911,13 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 1,
column: 22,
endColumn: 2,
messageId: 'promisesWithAsyncAssertionsMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 2,
column: 3,
Expand All @@ -859,6 +939,13 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 1,
column: 22,
endColumn: 2,
messageId: 'promisesWithAsyncAssertionsMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 2,
column: 3,
Expand Down Expand Up @@ -901,6 +988,13 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 1,
column: 22,
endColumn: 2,
messageId: 'promisesWithAsyncAssertionsMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 2,
column: 3,
Expand All @@ -924,6 +1018,12 @@ ruleTester.run('valid-expect', rule, {
`,
options: [{ alwaysAwait: true }],
errors: [
{
line: 1,
column: 22,
endColumn: 2,
messageId: 'promisesWithAsyncAssertionsMustBeAwaited',
},
{
line: 2,
column: 3,
Expand Down Expand Up @@ -951,6 +1051,14 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 1,
column: 22,
endLine: 6,
endColumn: 2,
messageId: 'promisesWithAsyncAssertionsMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 2,
column: 3,
Expand Down Expand Up @@ -980,6 +1088,14 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 1,
column: 22,
endLine: 6,
endColumn: 2,
messageId: 'promisesWithAsyncAssertionsMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 2,
column: 3,
Expand Down Expand Up @@ -1008,6 +1124,22 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 1,
column: 22,
endLine: 6,
endColumn: 2,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 1,
column: 22,
endLine: 6,
endColumn: 2,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 3,
column: 5,
Expand Down Expand Up @@ -1038,12 +1170,24 @@ ruleTester.run('valid-expect', rule, {
output: dedent`
test("valid-expect", async () => {
const assertions = [
expect(Promise.resolve(2)).toResolve(),
expect(Promise.resolve(3)).toReject(),
await expect(Promise.resolve(2)).toResolve(),
await expect(Promise.resolve(3)).toReject(),
]
});
`,
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand Down Expand Up @@ -1076,6 +1220,18 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
column: 22,
line: 1,
},
{
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
Expand Down Expand Up @@ -1116,6 +1272,14 @@ ruleTester.run('valid-expect', rule, {
});
`,
errors: [
{
line: 2,
column: 71,
endLine: 4,
endColumn: 4,
messageId: 'asyncMustBeAwaited',
data: { orReturned: ' or returned' },
},
{
line: 3,
column: 5,
Expand Down
Loading

0 comments on commit ae8ecac

Please sign in to comment.