Skip to content

Commit 92012a6

Browse files
committed
test: remove duplicate cases
1 parent 7a7a5fd commit 92012a6

13 files changed

+82
-190
lines changed

tests/create-testing-library-rule.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ ruleTester.run(RULE_NAME, rule, {
196196

197197
// cases: weird scenarios to check guard against parent nodes
198198
'expect(element).not()',
199-
'expect(element).not()',
200199

201200
// Test Cases for Queries and Aggressive Queries Reporting
202201
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ruleTester.run(RULE_NAME, rule, {
142142
'testing-library/utils-module': 'test-utils',
143143
},
144144
code: `
145-
import { fireEvent } from 'somewhere-else'
145+
import { fireEvent } from 'somewhere-else' // not ${testingFramework}
146146
test('unhandled promise from event not related to TL is valid', async () => {
147147
fireEvent.${eventMethod}(getByLabelText('username'))
148148
})
@@ -154,7 +154,7 @@ ruleTester.run(RULE_NAME, rule, {
154154
'testing-library/utils-module': 'test-utils',
155155
},
156156
code: `
157-
import { fireEvent } from 'test-utils'
157+
import { fireEvent } from 'test-utils' // implicitly ${testingFramework}
158158
test('await promise from event method imported from custom module is valid', async () => {
159159
await fireEvent.${eventMethod}(getByLabelText('username'))
160160
})
@@ -166,7 +166,7 @@ ruleTester.run(RULE_NAME, rule, {
166166
// valid use case without call expression
167167
// so there is no innermost function scope found
168168
code: `
169-
import { fireEvent } from 'test-utils'
169+
import { fireEvent } from 'test-utils' // implicitly using ${testingFramework}
170170
test('edge case for innermost function without call expression', async () => {
171171
function triggerEvent() {
172172
doSomething()
@@ -611,7 +611,7 @@ ruleTester.run(RULE_NAME, rule, {
611611
'testing-library/utils-module': 'test-utils',
612612
},
613613
code: `
614-
import { fireEvent } from 'test-utils'
614+
import { fireEvent } from 'test-utils' // implicitly using ${testingFramework}
615615
test(
616616
'unhandled promise from event method imported from custom module with aggressive reporting opted-out is invalid',
617617
() => {
@@ -628,7 +628,7 @@ ruleTester.run(RULE_NAME, rule, {
628628
],
629629
options: [{ eventModule: 'fireEvent' }],
630630
output: `
631-
import { fireEvent } from 'test-utils'
631+
import { fireEvent } from 'test-utils' // implicitly using ${testingFramework}
632632
test(
633633
'unhandled promise from event method imported from custom module with aggressive reporting opted-out is invalid',
634634
async () => {

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ ruleTester.run(RULE_NAME, rule, {
126126
'testing-library/utils-module': 'test-utils',
127127
},
128128
code: `
129-
import { ${asyncUtil} } from 'some-other-library';
129+
import { ${asyncUtil} } from 'some-other-library'; // rather than ${testingFramework}
130130
test(
131131
'aggressive reporting disabled - util "${asyncUtil}" which is not related to testing library is valid',
132132
async () => {
@@ -140,7 +140,7 @@ ruleTester.run(RULE_NAME, rule, {
140140
'testing-library/utils-module': 'test-utils',
141141
},
142142
code: `
143-
import * as asyncUtils from 'some-other-library';
143+
import * as asyncUtils from 'some-other-library'; // rather than ${testingFramework}
144144
test(
145145
'aggressive reporting disabled - util "asyncUtils.${asyncUtil}" which is not related to testing library is valid',
146146
async () => {
@@ -242,7 +242,7 @@ ruleTester.run(RULE_NAME, rule, {
242242
code: `
243243
test('using unrelated promises with Promise.all is valid', async () => {
244244
Promise.all([
245-
waitForNotRelatedToTestingLibrary(),
245+
waitForNotRelatedToTestingLibrary(), // completely unrelated to ${testingFramework}
246246
promise1,
247247
await foo().then(() => baz())
248248
])
@@ -262,6 +262,7 @@ ruleTester.run(RULE_NAME, rule, {
262262
},
263263
...ASYNC_UTILS.map((asyncUtil) => ({
264264
code: `
265+
// using ${testingFramework} implicitly
265266
function setup() {
266267
const utils = render(<MyComponent />);
267268
@@ -297,7 +298,7 @@ ruleTester.run(RULE_NAME, rule, {
297298
...ASYNC_UTILS.map((asyncUtil) => ({
298299
code: `
299300
import React from 'react';
300-
import { render, act } from '@testing-library/react';
301+
import { render, act } from '${testingFramework}';
301302
302303
const doWithAct = async (timeout) => {
303304
await act(async () => await ${asyncUtil}(screen.getByTestId('my-test')));
@@ -491,7 +492,7 @@ ruleTester.run(RULE_NAME, rule, {
491492
(asyncUtil) =>
492493
({
493494
code: `
494-
import { ${asyncUtil} } from 'some-other-library';
495+
import { ${asyncUtil} } from 'some-other-library'; // rather than ${testingFramework}
495496
test(
496497
'aggressive reporting - util "${asyncUtil}" which is not related to testing library is invalid',
497498
async () => {
@@ -539,7 +540,7 @@ ruleTester.run(RULE_NAME, rule, {
539540
(asyncUtil) =>
540541
({
541542
code: `
542-
import * as asyncUtils from 'some-other-library';
543+
import * as asyncUtils from 'some-other-library'; // rather than ${testingFramework}
543544
test(
544545
'aggressive reporting - util "asyncUtils.${asyncUtil}" which is not related to testing library is invalid',
545546
async () => {
@@ -561,6 +562,7 @@ ruleTester.run(RULE_NAME, rule, {
561562
(asyncUtil) =>
562563
({
563564
code: `
565+
// using ${testingFramework} implicitly
564566
function setup() {
565567
const utils = render(<MyComponent />);
566568
@@ -578,7 +580,7 @@ ruleTester.run(RULE_NAME, rule, {
578580
`,
579581
errors: [
580582
{
581-
line: 14,
583+
line: 15,
582584
column: 11,
583585
messageId: 'asyncUtilWrapper',
584586
data: { name: 'waitForAsyncUtil' },
@@ -590,6 +592,7 @@ ruleTester.run(RULE_NAME, rule, {
590592
(asyncUtil) =>
591593
({
592594
code: `
595+
// using ${testingFramework} implicitly
593596
function setup() {
594597
const utils = render(<MyComponent />);
595598
@@ -608,7 +611,7 @@ ruleTester.run(RULE_NAME, rule, {
608611
`,
609612
errors: [
610613
{
611-
line: 15,
614+
line: 16,
612615
column: 11,
613616
messageId: 'asyncUtilWrapper',
614617
data: { name: 'myAlias' },
@@ -620,6 +623,7 @@ ruleTester.run(RULE_NAME, rule, {
620623
(asyncUtil) =>
621624
({
622625
code: `
626+
// using ${testingFramework} implicitly
623627
function setup() {
624628
const utils = render(<MyComponent />);
625629
@@ -637,7 +641,7 @@ ruleTester.run(RULE_NAME, rule, {
637641
`,
638642
errors: [
639643
{
640-
line: 14,
644+
line: 15,
641645
column: 17,
642646
messageId: 'asyncUtilWrapper',
643647
data: { name: 'waitForAsyncUtil' },
@@ -649,6 +653,7 @@ ruleTester.run(RULE_NAME, rule, {
649653
(asyncUtil) =>
650654
({
651655
code: `
656+
// using ${testingFramework} implicitly
652657
function setup() {
653658
const utils = render(<MyComponent />);
654659
@@ -666,7 +671,7 @@ ruleTester.run(RULE_NAME, rule, {
666671
`,
667672
errors: [
668673
{
669-
line: 14,
674+
line: 15,
670675
column: 11,
671676
messageId: 'asyncUtilWrapper',
672677
data: { name: 'myAlias' },
@@ -678,6 +683,7 @@ ruleTester.run(RULE_NAME, rule, {
678683
(asyncUtil) =>
679684
({
680685
code: `
686+
// using ${testingFramework} implicitly
681687
function setup() {
682688
const utils = render(<MyComponent />);
683689
@@ -694,7 +700,7 @@ ruleTester.run(RULE_NAME, rule, {
694700
`,
695701
errors: [
696702
{
697-
line: 13,
703+
line: 14,
698704
column: 19,
699705
messageId: 'asyncUtilWrapper',
700706
data: { name: 'waitForAsyncUtil' },
@@ -706,6 +712,7 @@ ruleTester.run(RULE_NAME, rule, {
706712
(asyncUtil) =>
707713
({
708714
code: `
715+
// using ${testingFramework} implicitly
709716
function setup() {
710717
const utils = render(<MyComponent />);
711718
@@ -723,7 +730,7 @@ ruleTester.run(RULE_NAME, rule, {
723730
`,
724731
errors: [
725732
{
726-
line: 14,
733+
line: 15,
727734
column: 11,
728735
messageId: 'asyncUtilWrapper',
729736
data: { name: 'myAlias' },

tests/lib/rules/no-await-sync-events.test.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -289,51 +289,6 @@ ruleTester.run(RULE_NAME, rule, {
289289
} as const)
290290
),
291291

292-
// sync fireEvent methods with await operator are not valid
293-
// when only fire-event set in eventModules
294-
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) =>
295-
FIRE_EVENT_FUNCTIONS.map(
296-
(func) =>
297-
({
298-
code: `
299-
import { fireEvent } from '${testingFramework}';
300-
test('should report fireEvent.${func} sync event awaited', async() => {
301-
await fireEvent.${func}('foo');
302-
});
303-
`,
304-
errors: [
305-
{
306-
line: 4,
307-
column: 17,
308-
messageId: 'noAwaitSyncEvents',
309-
data: { name: `fireEvent.${func}` },
310-
},
311-
],
312-
} as const)
313-
)
314-
),
315-
316-
...USER_EVENT_SYNC_FUNCTIONS.map(
317-
(func) =>
318-
({
319-
code: `
320-
import userEvent from '@testing-library/user-event';
321-
test('should report userEvent.${func} sync event awaited', async() => {
322-
await userEvent.${func}('foo');
323-
});
324-
`,
325-
options: [{ eventModules: ['user-event'] }],
326-
errors: [
327-
{
328-
line: 4,
329-
column: 17,
330-
messageId: 'noAwaitSyncEvents',
331-
data: { name: `userEvent.${func}` },
332-
},
333-
],
334-
} as const)
335-
),
336-
337292
{
338293
code: `
339294
import userEvent from '@testing-library/user-event';

tests/lib/rules/no-debugging-utils.test.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -434,19 +434,6 @@ ruleTester.run(RULE_NAME, rule, {
434434
code: `
435435
import { screen } from '@testing-library/dom'
436436
screen.debug()
437-
`,
438-
errors: [
439-
{
440-
line: 3,
441-
column: 16,
442-
messageId: 'noDebug',
443-
},
444-
],
445-
},
446-
{
447-
code: `
448-
import { screen } from '@testing-library/dom'
449-
screen.logTestingPlaygroundURL()
450437
`,
451438
errors: [
452439
{
@@ -486,19 +473,6 @@ ruleTester.run(RULE_NAME, rule, {
486473
code: `
487474
import { screen } from '@testing-library/dom'
488475
screen.logTestingPlaygroundURL()
489-
`,
490-
errors: [
491-
{
492-
line: 3,
493-
column: 16,
494-
messageId: 'noDebug',
495-
},
496-
],
497-
},
498-
{
499-
code: `
500-
import { screen } from '@testing-library/dom'
501-
screen.logTestingPlaygroundURL()
502476
`,
503477
options: [{ utilsToCheckFor: {} }],
504478
errors: [
@@ -509,19 +483,6 @@ ruleTester.run(RULE_NAME, rule, {
509483
},
510484
],
511485
},
512-
{
513-
code: `
514-
import { screen } from '@testing-library/dom'
515-
screen.logTestingPlaygroundURL()
516-
`,
517-
errors: [
518-
{
519-
line: 3,
520-
column: 16,
521-
messageId: 'noDebug',
522-
},
523-
],
524-
},
525486
{
526487
settings: { 'testing-library/utils-module': 'test-utils' },
527488
code: `// aggressive reporting disabled

tests/lib/rules/no-dom-import.test.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,38 @@ ruleTester.run(RULE_NAME, rule, {
3131
'import { foo } from "foo"',
3232
'import "foo"',
3333
...SUPPORTED_TESTING_FRAMEWORKS.flatMap(({ oldName, newName }) =>
34-
[oldName, newName].flatMap((testingFramework) => [
35-
`import { fireEvent } from "${testingFramework}"`,
36-
`import * as testing from "${testingFramework}"`,
37-
`import "${testingFramework}"`,
38-
])
34+
[oldName, newName !== oldName ? newName : null].flatMap(
35+
(testingFramework) => {
36+
if (!testingFramework) {
37+
return [];
38+
}
39+
40+
return [
41+
`import { fireEvent } from "${testingFramework}"`,
42+
`import * as testing from "${testingFramework}"`,
43+
`import "${testingFramework}"`,
44+
];
45+
}
46+
)
3947
),
4048
'const { foo } = require("foo")',
4149
'require("foo")',
4250
'require("")',
4351
'require()',
4452
...SUPPORTED_TESTING_FRAMEWORKS.flatMap(({ oldName, newName }) =>
45-
[oldName, newName].flatMap((testingFramework) => [
46-
`const { fireEvent } = require("${testingFramework}")`,
47-
`const { fireEvent: testing } = require("${testingFramework}")`,
48-
`require("${testingFramework}")`,
49-
])
53+
[oldName, newName !== oldName ? newName : null].flatMap(
54+
(testingFramework) => {
55+
if (!testingFramework) {
56+
return [];
57+
}
58+
59+
return [
60+
`const { fireEvent } = require("${testingFramework}")`,
61+
`const { fireEvent: testing } = require("${testingFramework}")`,
62+
`require("${testingFramework}")`,
63+
];
64+
}
65+
)
5066
),
5167
{
5268
code: 'import { fireEvent } from "test-utils"',

0 commit comments

Comments
 (0)