Skip to content

Commit a8c1fe4

Browse files
committed
fix(await-async-utils): reference correct node name
1 parent 82ace49 commit a8c1fe4

File tree

2 files changed

+100
-9
lines changed

2 files changed

+100
-9
lines changed

lib/rules/await-async-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
8080
node,
8181
messageId: 'awaitAsyncUtil',
8282
data: {
83-
name: referenceNode.name,
83+
name: node.name,
8484
},
8585
});
8686
}

tests/lib/rules/await-async-utils.test.ts

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,31 @@ ruleTester.run(RULE_NAME, rule, {
250250
${asyncUtil}(() => getByLabelText('email'));
251251
});
252252
`,
253-
errors: [{ line: 5, column: 11, messageId: 'awaitAsyncUtil' }],
253+
errors: [
254+
{
255+
line: 5,
256+
column: 11,
257+
messageId: 'awaitAsyncUtil',
258+
data: { name: asyncUtil },
259+
},
260+
],
261+
})),
262+
...ASYNC_UTILS.map((asyncUtil) => ({
263+
code: `
264+
import { ${asyncUtil} } from '@testing-library/dom';
265+
test('${asyncUtil} util not waited is invalid', () => {
266+
doSomethingElse();
267+
const el = ${asyncUtil}(() => getByLabelText('email'));
268+
});
269+
`,
270+
errors: [
271+
{
272+
line: 5,
273+
column: 22,
274+
messageId: 'awaitAsyncUtil',
275+
data: { name: asyncUtil },
276+
},
277+
],
254278
})),
255279
...ASYNC_UTILS.map((asyncUtil) => ({
256280
code: `
@@ -260,7 +284,14 @@ ruleTester.run(RULE_NAME, rule, {
260284
asyncUtil.${asyncUtil}(() => getByLabelText('email'));
261285
});
262286
`,
263-
errors: [{ line: 5, column: 21, messageId: 'awaitAsyncUtil' }],
287+
errors: [
288+
{
289+
line: 5,
290+
column: 21,
291+
messageId: 'awaitAsyncUtil',
292+
data: { name: asyncUtil },
293+
},
294+
],
264295
})),
265296
...ASYNC_UTILS.map((asyncUtil) => ({
266297
code: `
@@ -270,7 +301,14 @@ ruleTester.run(RULE_NAME, rule, {
270301
const aPromise = ${asyncUtil}(() => getByLabelText('email'));
271302
});
272303
`,
273-
errors: [{ line: 5, column: 28, messageId: 'awaitAsyncUtil' }],
304+
errors: [
305+
{
306+
line: 5,
307+
column: 28,
308+
messageId: 'awaitAsyncUtil',
309+
data: { name: asyncUtil },
310+
},
311+
],
274312
})),
275313
...ASYNC_UTILS.map((asyncUtil) => ({
276314
code: `
@@ -282,8 +320,18 @@ ruleTester.run(RULE_NAME, rule, {
282320
});
283321
`,
284322
errors: [
285-
{ line: 4, column: 28, messageId: 'awaitAsyncUtil' },
286-
{ line: 6, column: 11, messageId: 'awaitAsyncUtil' },
323+
{
324+
line: 4,
325+
column: 28,
326+
messageId: 'awaitAsyncUtil',
327+
data: { name: asyncUtil },
328+
},
329+
{
330+
line: 6,
331+
column: 11,
332+
messageId: 'awaitAsyncUtil',
333+
data: { name: asyncUtil },
334+
},
287335
],
288336
})),
289337
...ASYNC_UTILS.map((asyncUtil) => ({
@@ -299,7 +347,14 @@ ruleTester.run(RULE_NAME, rule, {
299347
waitForSomethingAsync()
300348
});
301349
`,
302-
errors: [{ messageId: 'asyncUtilWrapper', line: 10, column: 11 }],
350+
errors: [
351+
{
352+
messageId: 'asyncUtilWrapper',
353+
line: 10,
354+
column: 11,
355+
data: { name: 'waitForSomethingAsync' },
356+
},
357+
],
303358
})),
304359
...ASYNC_UTILS.map((asyncUtil) => ({
305360
code: `
@@ -311,7 +366,36 @@ ruleTester.run(RULE_NAME, rule, {
311366
${asyncUtil}();
312367
});
313368
`,
314-
errors: [{ line: 7, column: 11, messageId: 'awaitAsyncUtil' }],
369+
errors: [
370+
{
371+
line: 7,
372+
column: 11,
373+
messageId: 'awaitAsyncUtil',
374+
data: { name: asyncUtil },
375+
},
376+
],
377+
})),
378+
...ASYNC_UTILS.map((asyncUtil) => ({
379+
code: `
380+
import { ${asyncUtil}, render } from '@testing-library/dom';
381+
382+
function waitForSomethingAsync() {
383+
return ${asyncUtil}(() => somethingAsync())
384+
}
385+
386+
test('unhandled promise from function wrapping ${asyncUtil} util is invalid', async () => {
387+
render()
388+
const el = waitForSomethingAsync()
389+
});
390+
`,
391+
errors: [
392+
{
393+
messageId: 'asyncUtilWrapper',
394+
line: 10,
395+
column: 22,
396+
data: { name: 'waitForSomethingAsync' },
397+
},
398+
],
315399
})),
316400
...ASYNC_UTILS.map((asyncUtil) => ({
317401
code: `
@@ -323,7 +407,14 @@ ruleTester.run(RULE_NAME, rule, {
323407
asyncUtils.${asyncUtil}();
324408
});
325409
`,
326-
errors: [{ line: 7, column: 22, messageId: 'awaitAsyncUtil' }],
410+
errors: [
411+
{
412+
line: 7,
413+
column: 22,
414+
messageId: 'awaitAsyncUtil',
415+
data: { name: asyncUtil },
416+
},
417+
],
327418
})),
328419
],
329420
});

0 commit comments

Comments
 (0)