Skip to content

Commit

Permalink
test(eslint-plugin): add optional chaining cases for await-thenable (
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Nov 11, 2021
1 parent 49d6444 commit f409726
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/eslint-plugin/tests/rules/await-thenable.test.ts
Expand Up @@ -176,6 +176,26 @@ async function test() {
await bluebird;
}
`,
`
const doSomething = async (
obj1: { a?: { b?: { c?: () => Promise<void> } } },
obj2: { a?: { b?: { c: () => Promise<void> } } },
obj3: { a?: { b: { c?: () => Promise<void> } } },
obj4: { a: { b: { c?: () => Promise<void> } } },
obj5: { a?: () => { b?: { c?: () => Promise<void> } } },
obj6?: { a: { b: { c?: () => Promise<void> } } },
callback?: () => Promise<void>,
): Promise<void> => {
await obj1.a?.b?.c?.();
await obj2.a?.b?.c();
await obj3.a?.b.c?.();
await obj4.a.b.c?.();
await obj5.a?.().b?.c?.();
await obj6?.a.b.c?.();
await callback?.();
};
`,
],

invalid: [
Expand Down Expand Up @@ -228,5 +248,57 @@ async function test() {
},
],
},
{
code: `
const doSomething = async (
obj1: { a?: { b?: { c?: () => void } } },
obj2: { a?: { b?: { c: () => void } } },
obj3: { a?: { b: { c?: () => void } } },
obj4: { a: { b: { c?: () => void } } },
obj5: { a?: () => { b?: { c?: () => void } } },
obj6?: { a: { b: { c?: () => void } } },
callback?: () => void,
): Promise<void> => {
await obj1.a?.b?.c?.();
await obj2.a?.b?.c();
await obj3.a?.b.c?.();
await obj4.a.b.c?.();
await obj5.a?.().b?.c?.();
await obj6?.a.b.c?.();
await callback?.();
};
`,
errors: [
{
line: 11,
messageId,
},
{
line: 12,
messageId,
},
{
line: 13,
messageId,
},
{
line: 14,
messageId,
},
{
line: 15,
messageId,
},
{
line: 16,
messageId,
},
{
line: 18,
messageId,
},
],
},
],
});

0 comments on commit f409726

Please sign in to comment.