Skip to content

Commit 468243f

Browse files
committed
test: refactor @testing-library/angular tests
1 parent 49b79ad commit 468243f

18 files changed

+136
-161
lines changed

lib/rules/no-dom-import.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
4949
if (framework) {
5050
// marko TL is called @marko/testing-library
5151
const correctModuleName =
52-
framework === 'marko'
53-
? moduleName.replace('dom-', `@${framework}/`)
52+
framework === 'angular'
53+
? '@testing-library/angular'
54+
: framework === 'marko'
55+
? '@marko/testing-library'
5456
: moduleName.replace('dom', framework);
5557
context.report({
5658
node,

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

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ruleTester = createRuleTester();
1313

1414
const SUPPORTED_TESTING_FRAMEWORKS = [
1515
'@testing-library/dom',
16+
'@testing-library/angular',
1617
'@testing-library/react',
1718
'@marko/testing-library',
1819
];

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ruleTester = createRuleTester();
66

77
const SUPPORTED_TESTING_FRAMEWORKS = [
88
'@testing-library/dom',
9+
'@testing-library/angular',
910
'@marko/testing-library',
1011
];
1112

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ruleTester = createRuleTester();
99

1010
const SUPPORTED_TESTING_FRAMEWORKS = [
1111
'@testing-library/dom',
12+
'@testing-library/angular',
1213
'@testing-library/react',
1314
'@marko/testing-library',
1415
];

tests/lib/rules/no-container.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createRuleTester } from '../test-utils';
44
const ruleTester = createRuleTester();
55

66
const SUPPORTED_TESTING_FRAMEWORKS = [
7+
'@testing-library/angular',
78
'@testing-library/react',
89
'@marko/testing-library',
910
];

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createRuleTester } from '../test-utils';
44
const ruleTester = createRuleTester();
55

66
const SUPPORTED_TESTING_FRAMEWORKS = [
7+
'@testing-library/angular',
78
'@testing-library/react',
89
'@marko/testing-library',
910
];

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

+116-159
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,50 @@ import { createRuleTester } from '../test-utils';
44
const ruleTester = createRuleTester();
55

66
const SUPPORTED_TESTING_FRAMEWORKS = [
7-
'react-testing-library',
8-
'@testing-library/react',
9-
'@marko/testing-library',
7+
{
8+
configOption: 'angular',
9+
oldName: '@testing-library/angular',
10+
newName: '@testing-library/angular',
11+
},
12+
{
13+
configOption: 'react',
14+
oldName: 'react-testing-library',
15+
newName: '@testing-library/react',
16+
},
17+
{
18+
configOption: 'vue',
19+
oldName: 'vue-testing-library',
20+
newName: '@testing-library/vue',
21+
},
22+
{
23+
configOption: 'marko',
24+
oldName: '@marko/testing-library',
25+
newName: '@marko/testing-library',
26+
},
1027
];
1128

1229
ruleTester.run(RULE_NAME, rule, {
1330
valid: [
1431
'import { foo } from "foo"',
1532
'import "foo"',
16-
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
17-
`import { fireEvent } from "${testingFramework}"`,
18-
`import * as testing from "${testingFramework}"`,
19-
`import "${testingFramework}"`,
20-
]),
33+
...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+
])
39+
),
2140
'const { foo } = require("foo")',
2241
'require("foo")',
2342
'require("")',
2443
'require()',
25-
...SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
26-
`const { fireEvent } = require("${testingFramework}")`,
27-
`const { fireEvent: testing } = require("${testingFramework}")`,
28-
`require("${testingFramework}")`,
29-
]),
44+
...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+
])
50+
),
3051
{
3152
code: 'import { fireEvent } from "test-utils"',
3253
settings: { 'testing-library/utils-module': 'test-utils' },
@@ -59,192 +80,128 @@ ruleTester.run(RULE_NAME, rule, {
5980
// case: dom-testing-library imported with custom module setting
6081
import { fireEvent } from "dom-testing-library"`,
6182
},
62-
{
63-
code: 'import { fireEvent } from "dom-testing-library"',
64-
options: ['react'],
65-
errors: [
66-
{
67-
messageId: 'noDomImportFramework',
68-
data: {
69-
module: 'react-testing-library',
70-
},
71-
},
72-
],
73-
output: `import { fireEvent } from "react-testing-library"`,
74-
},
75-
{
76-
code: 'import { fireEvent } from "dom-testing-library"',
77-
options: ['marko'],
78-
errors: [
79-
{
80-
messageId: 'noDomImportFramework',
81-
data: {
82-
module: '@marko/testing-library',
83-
},
84-
},
85-
],
86-
output: `import { fireEvent } from "@marko/testing-library"`,
87-
},
88-
// Single quote or double quotes should not be replaced
89-
{
90-
code: `import { fireEvent } from 'dom-testing-library'`,
91-
options: ['react'],
92-
errors: [
93-
{
94-
messageId: 'noDomImportFramework',
95-
data: {
96-
module: 'react-testing-library',
97-
},
98-
},
99-
],
100-
output: `import { fireEvent } from 'react-testing-library'`,
101-
},
83+
...SUPPORTED_TESTING_FRAMEWORKS.flatMap(
84+
({ configOption, oldName, newName }) =>
85+
[true, false].flatMap((isOldImport) =>
86+
// Single quote or double quotes should not be replaced
87+
[`'`, `"`].flatMap((quote) => [
88+
{
89+
code: `const { fireEvent } = require(${quote}${
90+
isOldImport ? 'dom-testing-library' : '@testing-library/dom'
91+
}${quote})`,
92+
options: [configOption],
93+
errors: [
94+
{
95+
data: { module: isOldImport ? oldName : newName },
96+
messageId: 'noDomImportFramework',
97+
},
98+
],
99+
output: `const { fireEvent } = require(${quote}${
100+
isOldImport ? oldName : newName
101+
}${quote})`,
102+
} as const,
103+
{
104+
code: `import { fireEvent } from ${quote}${
105+
isOldImport ? 'dom-testing-library' : '@testing-library/dom'
106+
}${quote}`,
107+
options: [configOption],
108+
errors: [
109+
{
110+
data: { module: isOldImport ? oldName : newName },
111+
messageId: 'noDomImportFramework',
112+
},
113+
],
114+
output: `import { fireEvent } from ${quote}${
115+
isOldImport ? oldName : newName
116+
}${quote}`,
117+
} as const,
118+
])
119+
)
120+
),
102121
{
103122
code: 'import * as testing from "dom-testing-library"',
104-
errors: [
105-
{
106-
messageId: 'noDomImport',
107-
},
108-
],
123+
errors: [{ messageId: 'noDomImport' }],
109124
},
110125
{
111-
settings: {
112-
'testing-library/utils-module': 'test-utils',
113-
},
126+
settings: { 'testing-library/utils-module': 'test-utils' },
114127
code: `
115128
// case: dom-testing-library wildcard imported with custom module setting
116129
import * as testing from "dom-testing-library"`,
117-
errors: [
118-
{
119-
line: 3,
120-
messageId: 'noDomImport',
121-
},
122-
],
130+
errors: [{ line: 3, messageId: 'noDomImport' }],
123131
},
124132
{
125133
code: 'import { fireEvent } from "@testing-library/dom"',
126-
errors: [
127-
{
128-
messageId: 'noDomImport',
129-
},
130-
],
134+
errors: [{ messageId: 'noDomImport' }],
131135
},
132136
{
133-
settings: {
134-
'testing-library/utils-module': 'test-utils',
135-
},
137+
settings: { 'testing-library/utils-module': 'test-utils' },
136138
code: `
137139
// case: @testing-library/dom imported with custom module setting
138140
import { fireEvent } from "@testing-library/dom"`,
139-
errors: [
140-
{
141-
line: 3,
142-
messageId: 'noDomImport',
143-
},
144-
],
141+
errors: [{ line: 3, messageId: 'noDomImport' }],
145142
},
146143
{
147144
code: 'import * as testing from "@testing-library/dom"',
148-
errors: [
149-
{
150-
messageId: 'noDomImport',
151-
},
152-
],
145+
errors: [{ messageId: 'noDomImport' }],
153146
},
154147
{
155148
code: 'import "dom-testing-library"',
156-
errors: [
157-
{
158-
messageId: 'noDomImport',
159-
},
160-
],
149+
errors: [{ messageId: 'noDomImport' }],
161150
},
162151
{
163152
code: 'import "@testing-library/dom"',
164-
errors: [
165-
{
166-
messageId: 'noDomImport',
167-
},
168-
],
153+
errors: [{ messageId: 'noDomImport' }],
169154
},
170155
{
171156
code: 'const { fireEvent } = require("dom-testing-library")',
172-
errors: [
173-
{
174-
messageId: 'noDomImport',
175-
},
176-
],
157+
errors: [{ messageId: 'noDomImport' }],
177158
},
178159
{
179-
settings: {
180-
'testing-library/utils-module': 'test-utils',
181-
},
160+
settings: { 'testing-library/utils-module': 'test-utils' },
182161
code: `
183162
// case: dom-testing-library required with custom module setting
184163
const { fireEvent } = require("dom-testing-library")`,
185-
errors: [
186-
{
187-
line: 3,
188-
messageId: 'noDomImport',
189-
},
190-
],
164+
errors: [{ line: 3, messageId: 'noDomImport' }],
191165
},
192166
{
193167
code: 'const { fireEvent } = require("@testing-library/dom")',
194-
errors: [
195-
{
196-
messageId: 'noDomImport',
197-
},
198-
],
199-
},
200-
{
201-
code: 'const { fireEvent } = require("@testing-library/dom")',
202-
options: ['vue'],
203-
errors: [
204-
{
205-
messageId: 'noDomImportFramework',
206-
data: {
207-
module: '@testing-library/vue',
208-
},
209-
},
210-
],
211-
output: 'const { fireEvent } = require("@testing-library/vue")',
212-
},
213-
{
214-
settings: {
215-
'testing-library/utils-module': 'test-utils',
216-
},
217-
code: `
218-
// case: @testing-library/dom required with custom module setting
219-
const { fireEvent } = require("@testing-library/dom")`,
220-
options: ['vue'],
221-
errors: [
222-
{
223-
messageId: 'noDomImportFramework',
224-
data: {
225-
module: '@testing-library/vue',
226-
},
227-
},
228-
],
229-
output: `
230-
// case: @testing-library/dom required with custom module setting
231-
const { fireEvent } = require("@testing-library/vue")`,
232-
},
168+
errors: [{ messageId: 'noDomImport' }],
169+
},
170+
...SUPPORTED_TESTING_FRAMEWORKS.flatMap(
171+
({ configOption, oldName, newName }) =>
172+
[true, false].map(
173+
(isOldImport) =>
174+
({
175+
settings: { 'testing-library/utils-module': 'test-utils' },
176+
code: `
177+
// case: @testing-library/dom required with custom module setting
178+
const { fireEvent } = require("${
179+
isOldImport ? 'dom-testing-library' : '@testing-library/dom'
180+
}")
181+
`,
182+
options: [configOption],
183+
errors: [
184+
{
185+
data: { module: isOldImport ? oldName : newName },
186+
messageId: 'noDomImportFramework',
187+
},
188+
],
189+
output: `
190+
// case: @testing-library/dom required with custom module setting
191+
const { fireEvent } = require("${
192+
isOldImport ? oldName : newName
193+
}")
194+
`,
195+
} as const)
196+
)
197+
),
233198
{
234199
code: 'require("dom-testing-library")',
235-
errors: [
236-
{
237-
messageId: 'noDomImport',
238-
},
239-
],
200+
errors: [{ messageId: 'noDomImport' }],
240201
},
241202
{
242203
code: 'require("@testing-library/dom")',
243-
errors: [
244-
{
245-
messageId: 'noDomImport',
246-
},
247-
],
204+
errors: [{ messageId: 'noDomImport' }],
248205
},
249206
],
250207
});

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createRuleTester } from '../test-utils';
44
const ruleTester = createRuleTester();
55

66
const SUPPORTED_TESTING_FRAMEWORKS = [
7+
'@testing-library/angular',
78
'@testing-library/react',
89
'@marko/testing-library',
910
];

0 commit comments

Comments
 (0)