Skip to content

Commit eaa8df3

Browse files
committed
refactor: update test case types to use rule-tester types
1 parent 984f245 commit eaa8df3

6 files changed

+70
-56
lines changed

tests/lib/rules/consistent-data-testid.test.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { type TSESLint } from '@typescript-eslint/utils';
1+
import {
2+
type InvalidTestCase,
3+
type ValidTestCase,
4+
} from '@typescript-eslint/rule-tester';
25

36
import rule, {
47
MessageIds,
@@ -9,9 +12,9 @@ import { createRuleTester } from '../test-utils';
912

1013
const ruleTester = createRuleTester();
1114

12-
type ValidTestCase = TSESLint.ValidTestCase<Options>;
13-
type InvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
14-
type TestCase = InvalidTestCase | ValidTestCase;
15+
type RuleValidTestCase = ValidTestCase<Options>;
16+
type RuleInvalidTestCase = InvalidTestCase<MessageIds, Options>;
17+
type TestCase = RuleValidTestCase | RuleInvalidTestCase;
1518
const disableAggressiveReporting = <T extends TestCase>(array: T[]): T[] =>
1619
array.map((testCase) => ({
1720
...testCase,
@@ -22,11 +25,11 @@ const disableAggressiveReporting = <T extends TestCase>(array: T[]): T[] =>
2225
},
2326
}));
2427

25-
const validTestCases: ValidTestCase[] = [
28+
const validTestCases: RuleValidTestCase[] = [
2629
{
2730
code: `
2831
import React from 'react';
29-
32+
3033
const TestComponent = props => {
3134
return (
3235
<div data-testid="cool">
@@ -40,7 +43,7 @@ const validTestCases: ValidTestCase[] = [
4043
{
4144
code: `
4245
import React from 'react';
43-
46+
4447
const TestComponent = props => {
4548
return (
4649
<div className="cool">
@@ -54,7 +57,7 @@ const validTestCases: ValidTestCase[] = [
5457
{
5558
code: `
5659
import React from 'react';
57-
60+
5861
const TestComponent = props => {
5962
return (
6063
<div data-testid="Awesome__CoolStuff">
@@ -73,7 +76,7 @@ const validTestCases: ValidTestCase[] = [
7376
{
7477
code: `
7578
import React from 'react';
76-
79+
7780
const TestComponent = props => {
7881
return (
7982
<div data-testid="Awesome">
@@ -92,7 +95,7 @@ const validTestCases: ValidTestCase[] = [
9295
{
9396
code: `
9497
import React from 'react';
95-
98+
9699
const TestComponent = props => {
97100
return (
98101
<div data-testid="Parent">
@@ -111,7 +114,7 @@ const validTestCases: ValidTestCase[] = [
111114
{
112115
code: `
113116
import React from 'react';
114-
117+
115118
const TestComponent = props => {
116119
return (
117120
<div data-testid="Parent">
@@ -130,7 +133,7 @@ const validTestCases: ValidTestCase[] = [
130133
{
131134
code: `
132135
import React from 'react';
133-
136+
134137
const TestComponent = props => {
135138
return (
136139
<div data-testid="wrong" custom-attr="right-1">
@@ -149,7 +152,7 @@ const validTestCases: ValidTestCase[] = [
149152
{
150153
code: `
151154
import React from 'react';
152-
155+
153156
const TestComponent = props => {
154157
return (
155158
<div another-custom-attr="right-1" custom-attr="right-2">
@@ -168,7 +171,7 @@ const validTestCases: ValidTestCase[] = [
168171
{
169172
code: `
170173
import React from 'react';
171-
174+
172175
const TestComponent = props => {
173176
return (
174177
<div data-test-id="Parent">
@@ -188,7 +191,7 @@ const validTestCases: ValidTestCase[] = [
188191
{
189192
code: `
190193
import React from 'react';
191-
194+
192195
const TestComponent = props => {
193196
const dynamicTestId = 'somethingDynamic';
194197
return (
@@ -205,7 +208,7 @@ const validTestCases: ValidTestCase[] = [
205208
{
206209
code: `
207210
import React from 'react';
208-
211+
209212
const TestComponent = props => {
210213
return (
211214
<div data-testid="__CoolStuff">
@@ -224,7 +227,7 @@ const validTestCases: ValidTestCase[] = [
224227
{
225228
code: `
226229
import React from 'react';
227-
230+
228231
const TestComponent = props => {
229232
return (
230233
<div data-testid="__CoolStuff">
@@ -244,7 +247,7 @@ const validTestCases: ValidTestCase[] = [
244247
{
245248
code: `
246249
import React from 'react';
247-
250+
248251
const TestComponent = props => {
249252
return (
250253
<div data-testid="__CoolStuff">
@@ -262,11 +265,11 @@ const validTestCases: ValidTestCase[] = [
262265
filename: '/my/cool/file/path/[...wildcard].js',
263266
},
264267
];
265-
const invalidTestCases: InvalidTestCase[] = [
268+
const invalidTestCases: RuleInvalidTestCase[] = [
266269
{
267270
code: `
268271
import React from 'react';
269-
272+
270273
const TestComponent = props => {
271274
return (
272275
<div data-testid="Awesome__CoolStuff">
@@ -291,7 +294,7 @@ const invalidTestCases: InvalidTestCase[] = [
291294
{
292295
code: `
293296
import React from 'react';
294-
297+
295298
const TestComponent = props => {
296299
return (
297300
<div data-testid="Nope">
@@ -321,7 +324,7 @@ const invalidTestCases: InvalidTestCase[] = [
321324
{
322325
code: `
323326
import React from 'react';
324-
327+
325328
const TestComponent = props => {
326329
return (
327330
<div data-testid="Parent__cool" my-custom-attr="WrongComponent__cool">
@@ -352,7 +355,7 @@ const invalidTestCases: InvalidTestCase[] = [
352355
{
353356
code: `
354357
import React from 'react';
355-
358+
356359
const TestComponent = props => {
357360
return (
358361
<div custom-attr="wrong" another-custom-attr="wrong">
@@ -391,7 +394,7 @@ const invalidTestCases: InvalidTestCase[] = [
391394
{
392395
code: `
393396
import React from 'react';
394-
397+
395398
const TestComponent = props => {
396399
return (
397400
<div data-testid="WrongComponent__cool">
@@ -421,7 +424,7 @@ const invalidTestCases: InvalidTestCase[] = [
421424
{
422425
code: ` // test for custom message
423426
import React from 'react';
424-
427+
425428
const TestComponent = props => {
426429
return (
427430
<div data-testid="snake_case_value">

tests/lib/rules/no-unnecessary-act.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { type TSESLint } from '@typescript-eslint/utils';
1+
import {
2+
type InvalidTestCase,
3+
type ValidTestCase,
4+
} from '@typescript-eslint/rule-tester';
25

36
import rule, {
47
MessageIds,
@@ -9,9 +12,9 @@ import { createRuleTester } from '../test-utils';
912

1013
const ruleTester = createRuleTester();
1114

12-
type ValidTestCase = TSESLint.ValidTestCase<Options>;
13-
type InvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
14-
type TestCase = InvalidTestCase | ValidTestCase;
15+
type RuleValidTestCase = ValidTestCase<Options>;
16+
type RuleInvalidTestCase = InvalidTestCase<MessageIds, Options>;
17+
type TestCase = RuleInvalidTestCase | RuleValidTestCase;
1518

1619
const addOptions = <T extends TestCase>(
1720
array: T[],
@@ -37,7 +40,7 @@ const SUPPORTED_TESTING_FRAMEWORKS = [
3740
['@marko/testing-library', 'Marko TL'],
3841
];
3942

40-
const validNonStrictTestCases: ValidTestCase[] = [
43+
const validNonStrictTestCases: RuleValidTestCase[] = [
4144
{
4245
code: `// case: RTL act wrapping both RTL and non-RTL calls
4346
import { act, render, waitFor } from '@testing-library/react'
@@ -62,7 +65,7 @@ const validNonStrictTestCases: ValidTestCase[] = [
6265
},
6366
];
6467

65-
const validTestCases: ValidTestCase[] = [
68+
const validTestCases: RuleValidTestCase[] = [
6669
...SUPPORTED_TESTING_FRAMEWORKS.map(([testingFramework, shortName]) => ({
6770
code: `// case: ${shortName} act wrapping non-${shortName} calls
6871
import { act } from '${testingFramework}'
@@ -214,7 +217,7 @@ const validTestCases: ValidTestCase[] = [
214217
})),
215218
];
216219

217-
const invalidStrictTestCases: InvalidTestCase[] =
220+
const invalidStrictTestCases: RuleInvalidTestCase[] =
218221
SUPPORTED_TESTING_FRAMEWORKS.flatMap(([testingFramework, shortName]) => [
219222
{
220223
code: `// case: ${shortName} act wrapping both ${shortName} and non-${shortName} calls with strict option
@@ -244,7 +247,7 @@ const invalidStrictTestCases: InvalidTestCase[] =
244247
},
245248
]);
246249

247-
const invalidTestCases: InvalidTestCase[] = [
250+
const invalidTestCases: RuleInvalidTestCase[] = [
248251
...SUPPORTED_TESTING_FRAMEWORKS.map(
249252
([testingFramework, shortName]) =>
250253
({

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { TSESLint } from '@typescript-eslint/utils';
1+
import {
2+
type InvalidTestCase,
3+
type ValidTestCase,
4+
} from '@typescript-eslint/rule-tester';
25

36
import rule, {
47
RULE_NAME,
@@ -26,9 +29,7 @@ function buildFindByMethod(queryMethod: string) {
2629
}
2730

2831
function createScenario<
29-
T extends
30-
| TSESLint.InvalidTestCase<MessageIds, []>
31-
| TSESLint.ValidTestCase<[]>,
32+
T extends InvalidTestCase<MessageIds, []> | ValidTestCase<[]>,
3233
>(callback: (waitMethod: string, queryMethod: string) => T) {
3334
return SYNC_QUERIES_COMBINATIONS.map((queryMethod) =>
3435
callback('waitFor', queryMethod)

tests/lib/rules/prefer-presence-queries.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { TSESLint } from '@typescript-eslint/utils';
1+
import {
2+
type InvalidTestCase,
3+
type ValidTestCase,
4+
} from '@typescript-eslint/rule-tester';
25

36
import rule, {
47
RULE_NAME,
@@ -17,8 +20,8 @@ const queryAllByQueries = ALL_QUERIES_METHODS.map(
1720
(method) => `queryAll${method}`
1821
);
1922

20-
type RuleValidTestCase = TSESLint.ValidTestCase<Options>;
21-
type RuleInvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
23+
type RuleValidTestCase = ValidTestCase<Options>;
24+
type RuleInvalidTestCase = InvalidTestCase<MessageIds, Options>;
2225

2326
type AssertionFnParams = {
2427
query: string;
@@ -921,7 +924,7 @@ ruleTester.run(RULE_NAME, rule, {
921924
// submit button exists
922925
const submitButton = screen.getByRole('button')
923926
fireEvent.click(submitButton)
924-
927+
925928
// right after clicking submit button it disappears
926929
expect(submitButton).not.toBeInTheDocument()
927930
`,

tests/lib/rules/prefer-query-matchers.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { TSESLint } from '@typescript-eslint/utils';
1+
import {
2+
type InvalidTestCase,
3+
type ValidTestCase,
4+
} from '@typescript-eslint/rule-tester';
25

36
import rule, {
47
RULE_NAME,
@@ -17,8 +20,8 @@ const queryAllByQueries = ALL_QUERIES_METHODS.map(
1720
(method) => `queryAll${method}`
1821
);
1922

20-
type RuleValidTestCase = TSESLint.ValidTestCase<Options>;
21-
type RuleInvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
23+
type RuleValidTestCase = ValidTestCase<Options>;
24+
type RuleInvalidTestCase = InvalidTestCase<MessageIds, Options>;
2225

2326
type AssertionFnParams = {
2427
query: string;

0 commit comments

Comments
 (0)