Skip to content

Commit 9d2d655

Browse files
CodingItWrongobsoke
andcommitted
feat: set default options to no configured entries to check for
Co-authored-by: Dale Karp <[email protected]>
1 parent 572a953 commit 9d2d655

File tree

2 files changed

+9
-70
lines changed

2 files changed

+9
-70
lines changed

lib/rules/prefer-query-matchers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
5858
},
5959
defaultOptions: [
6060
{
61-
validEntries: [{ query: 'get', matcher: 'toBeVisible' }],
61+
validEntries: [],
6262
},
6363
],
6464

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

+8-69
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,41 @@ type RuleInvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
2323
type AssertionFnParams = {
2424
query: string;
2525
matcher: string;
26-
includeDefaultOptionsCase?: boolean;
2726
options: Options;
2827
};
2928

3029
const getValidAssertions = ({
3130
query,
3231
matcher,
33-
includeDefaultOptionsCase = true,
3432
options,
3533
}: AssertionFnParams): RuleValidTestCase[] => {
3634
const code = `expect(${query}('Hello'))${matcher}`;
3735
const screenCode = `expect(screen.${query}('Hello'))${matcher}`;
3836
return [
39-
...(includeDefaultOptionsCase
40-
? [
41-
{
42-
name: `${code} with default options`,
43-
code,
44-
},
45-
]
46-
: []),
4737
{
48-
name: `${code} with provided options`,
38+
name: `${code} with default options of empty validEntries`,
4939
code,
50-
options,
5140
},
5241
{
53-
name: `${code} with no validEntries`,
42+
name: `${code} with provided options`,
5443
code,
55-
options: [{ validEntries: [] }],
44+
options,
5645
},
57-
...(includeDefaultOptionsCase
58-
? [
59-
{
60-
name: `${screenCode} with default options`,
61-
code,
62-
},
63-
]
64-
: []),
6546
{
66-
name: `${screenCode} with provided options`,
47+
name: `${screenCode} with default options of empty validEntries`,
6748
code: screenCode,
68-
options,
6949
},
7050
{
71-
name: `${screenCode} with no validEntries`,
51+
name: `${screenCode} with provided options`,
7252
code: screenCode,
73-
options: [{ validEntries: [] }],
53+
options,
7454
},
7555
];
7656
};
7757

7858
const getInvalidAssertions = ({
7959
query,
8060
matcher,
81-
includeDefaultOptionsCase = true,
8261
options,
8362
}: AssertionFnParams): RuleInvalidTestCase[] => {
8463
const code = `expect(${query}('Hello'))${matcher}`;
@@ -90,22 +69,6 @@ const getInvalidAssertions = ({
9069
},
9170
] = options;
9271
return [
93-
...(includeDefaultOptionsCase
94-
? [
95-
{
96-
name: `${code} with default options`,
97-
code,
98-
errors: [
99-
{
100-
messageId,
101-
line: 1,
102-
column: 8,
103-
data: { query: validEntry.query, matcher: validEntry.matcher },
104-
},
105-
],
106-
},
107-
]
108-
: []),
10972
{
11073
name: `${code} with provided options`,
11174
code,
@@ -119,22 +82,6 @@ const getInvalidAssertions = ({
11982
},
12083
],
12184
},
122-
...(includeDefaultOptionsCase
123-
? [
124-
{
125-
name: `${screenCode} with default options`,
126-
code: screenCode,
127-
errors: [
128-
{
129-
messageId,
130-
line: 1,
131-
column: 15,
132-
data: { query: validEntry.query, matcher: validEntry.matcher },
133-
},
134-
],
135-
},
136-
]
137-
: []),
13885
{
13986
name: `${screenCode} with provided options`,
14087
code: screenCode,
@@ -247,31 +194,27 @@ ruleTester.run(RULE_NAME, rule, {
247194
...getValidAssertions({
248195
query: queryName,
249196
matcher: '.toBeVisible()',
250-
includeDefaultOptionsCase: false,
251197
options: [
252198
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
253199
],
254200
}),
255201
...getValidAssertions({
256202
query: queryName,
257203
matcher: '.toBeHelloWorld()',
258-
includeDefaultOptionsCase: false,
259204
options: [
260205
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
261206
],
262207
}),
263208
...getValidAssertions({
264209
query: queryName,
265210
matcher: '.not.toBeVisible()',
266-
includeDefaultOptionsCase: false,
267211
options: [
268212
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
269213
],
270214
}),
271215
...getValidAssertions({
272216
query: queryName,
273217
matcher: '.not.toBeHelloWorld()',
274-
includeDefaultOptionsCase: false,
275218
options: [
276219
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
277220
],
@@ -293,31 +236,27 @@ ruleTester.run(RULE_NAME, rule, {
293236
...getValidAssertions({
294237
query: queryName,
295238
matcher: '.toBeVisible()',
296-
includeDefaultOptionsCase: false,
297239
options: [
298240
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
299241
],
300242
}),
301243
...getValidAssertions({
302244
query: queryName,
303245
matcher: '.toBeHelloWorld()',
304-
includeDefaultOptionsCase: false,
305246
options: [
306247
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
307248
],
308249
}),
309250
...getValidAssertions({
310251
query: queryName,
311252
matcher: '.not.toBeVisible()',
312-
includeDefaultOptionsCase: false,
313253
options: [
314254
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
315255
],
316256
}),
317257
...getValidAssertions({
318258
query: queryName,
319259
matcher: '.not.toBeHelloWorld()',
320-
includeDefaultOptionsCase: false,
321260
options: [
322261
{ validEntries: [{ query: 'query', matcher: 'toBeVisible' }] },
323262
],
@@ -371,7 +310,6 @@ ruleTester.run(RULE_NAME, rule, {
371310
...getInvalidAssertions({
372311
query: queryName,
373312
matcher: '.toBeHelloWorld()',
374-
includeDefaultOptionsCase: false,
375313
options: [
376314
{ validEntries: [{ query: 'query', matcher: 'toBeHelloWorld' }] },
377315
],
@@ -386,7 +324,6 @@ ruleTester.run(RULE_NAME, rule, {
386324
...getInvalidAssertions({
387325
query: queryName,
388326
matcher: '.toBeHelloWorld()',
389-
includeDefaultOptionsCase: false,
390327
options: [
391328
{ validEntries: [{ query: 'query', matcher: 'toBeHelloWorld' }] },
392329
],
@@ -425,6 +362,7 @@ ruleTester.run(RULE_NAME, rule, {
425362
// cases: indexing into an `AllBy` result within the expectation
426363
{
427364
code: 'expect(screen.queryAllByText("button")[1]).toBeVisible()',
365+
options: [{ validEntries: [{ query: 'get', matcher: 'toBeVisible' }] }],
428366
errors: [
429367
{
430368
messageId: 'wrongQueryForMatcher',
@@ -439,6 +377,7 @@ ruleTester.run(RULE_NAME, rule, {
439377
// case: asserting presence incorrectly with custom queryBy* query
440378
expect(queryByCustomQuery("button")).toBeVisible()
441379
`,
380+
options: [{ validEntries: [{ query: 'get', matcher: 'toBeVisible' }] }],
442381
errors: [
443382
{
444383
messageId: 'wrongQueryForMatcher',

0 commit comments

Comments
 (0)