Skip to content

Commit 5daaa0d

Browse files
committed
test: remove duplicate cases
1 parent 152e242 commit 5daaa0d

6 files changed

+82
-45
lines changed

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-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"',

tests/lib/rules/no-node-access.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ruleTester.run(RULE_NAME, rule, {
6161
},
6262
{
6363
code: `
64-
// case: code not related to testing library at all
64+
// case: code not related to ${testingFramework} at all
6565
ReactDOM.render(
6666
<CommProvider useDsa={false}>
6767
<ThemeProvider>
@@ -116,14 +116,14 @@ ruleTester.run(RULE_NAME, rule, {
116116
'testing-library/utils-module': 'test-utils',
117117
},
118118
code: `
119-
// case: custom module set but not imported (aggressive reporting limited)
119+
// case: custom module set but not imported using ${testingFramework} (aggressive reporting limited)
120120
const closestButton = document.getElementById('submit-btn').closest('button');
121121
expect(closestButton).toBeInTheDocument();
122122
`,
123123
},
124124
{
125125
code: `
126-
// case: without importing TL (aggressive reporting skipped)
126+
// case: without importing ${testingFramework} (aggressive reporting skipped)
127127
const closestButton = document.getElementById('submit-btn')
128128
expect(closestButton).toBeInTheDocument();
129129
`,
@@ -141,7 +141,7 @@ ruleTester.run(RULE_NAME, rule, {
141141
{
142142
// Example from discussions in issue #386
143143
code: `
144-
import { render } from '@testing-library/react';
144+
import { render } from '${testingFramework}';
145145
146146
function Wrapper({ children }) {
147147
// this should NOT be reported
@@ -165,7 +165,7 @@ ruleTester.run(RULE_NAME, rule, {
165165
'testing-library/utils-module': 'test-utils',
166166
},
167167
code: `
168-
// case: importing from custom module (aggressive reporting limited)
168+
// case: importing from custom module for ${testingFramework} (aggressive reporting limited)
169169
import 'test-utils';
170170
const closestButton = document.getElementById('submit-btn')
171171
expect(closestButton).toBeInTheDocument();

tests/lib/rules/prefer-find-by.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ruleTester.run(RULE_NAME, rule, {
4040
...ASYNC_QUERIES_COMBINATIONS.map((queryMethod) => ({
4141
code: `
4242
it('tests', async () => {
43-
const { ${queryMethod} } = setup()
43+
const { ${queryMethod} } = setup() // implicitly using ${testingFramework}
4444
const submitButton = await ${queryMethod}('foo')
4545
})
4646
`,
@@ -251,7 +251,7 @@ ruleTester.run(RULE_NAME, rule, {
251251
},
252252
// invalid code, as we need findBy* to be defined somewhere, but required for getting 100% coverage
253253
{
254-
code: `const submitButton = await waitFor(() => getByText('baz', { name: 'button' }))`,
254+
code: `const submitButton = await waitFor(() => getByText('baz', { name: 'button' })) // implicitly using ${testingFramework}`,
255255
errors: [
256256
{
257257
messageId: 'preferFindBy',
@@ -263,12 +263,12 @@ ruleTester.run(RULE_NAME, rule, {
263263
},
264264
},
265265
],
266-
output: `const submitButton = await findByText('baz', { name: 'button' })`,
266+
output: `const submitButton = await findByText('baz', { name: 'button' }) // implicitly using ${testingFramework}`,
267267
},
268268
// this code would be invalid too, as findByRole is not defined anywhere.
269269
{
270270
code: `
271-
const getByRole = render().getByRole
271+
const getByRole = render().getByRole // implicitly using ${testingFramework}
272272
const submitButton = await waitFor(() => getByRole('baz', { name: 'button' }))
273273
`,
274274
errors: [
@@ -283,7 +283,7 @@ ruleTester.run(RULE_NAME, rule, {
283283
},
284284
],
285285
output: `
286-
const getByRole = render().getByRole
286+
const getByRole = render().getByRole // implicitly using ${testingFramework}
287287
const submitButton = await findByRole('baz', { name: 'button' })
288288
`,
289289
},

0 commit comments

Comments
 (0)