@@ -89,6 +89,89 @@ ruleTester.run(RULE_NAME, rule, {
89
89
import { foo } from 'custom-module-forced-report'
90
90
` ,
91
91
} ,
92
+
93
+ // Test Cases for all settings mixed
94
+ {
95
+ settings : {
96
+ 'testing-library/module' : 'test-utils' ,
97
+ 'testing-library/filename-pattern' : 'testing-library\\.js' ,
98
+ } ,
99
+ code : `
100
+ // case: matching custom settings partially - module but not filename
101
+ import { render } from 'test-utils'
102
+ import { somethingElse } from 'another-module'
103
+ const foo = require('bar')
104
+
105
+ const utils = render();
106
+ ` ,
107
+ } ,
108
+ {
109
+ settings : {
110
+ 'testing-library/module' : 'test-utils' ,
111
+ 'testing-library/filename-pattern' : 'testing-library\\.js' ,
112
+ } ,
113
+ filename : 'MyComponent.testing-library.js' ,
114
+ code : `
115
+ // case: matching custom settings partially - filename but not module
116
+ import { render } from 'other-utils'
117
+ import { somethingElse } from 'another-module'
118
+ const foo = require('bar')
119
+
120
+ const utils = render();
121
+ ` ,
122
+ } ,
123
+
124
+ // Test Cases for Queries and Aggressive Queries Reporting
125
+ {
126
+ code : `
127
+ // case: custom method not matching "getBy*" variant pattern
128
+ getSomeElement('button')
129
+ ` ,
130
+ } ,
131
+ {
132
+ code : `
133
+ // case: custom method not matching "queryBy*" variant pattern
134
+ querySomeElement('button')
135
+ ` ,
136
+ } ,
137
+ {
138
+ settings : {
139
+ 'testing-library/module' : 'test-utils' ,
140
+ } ,
141
+ code : `
142
+ // case: built-in "getBy*" query not reported because custom module not imported
143
+ import { render } from 'other-module'
144
+ getByRole('button')
145
+ ` ,
146
+ } ,
147
+ {
148
+ settings : {
149
+ 'testing-library/module' : 'test-utils' ,
150
+ } ,
151
+ code : `
152
+ // case: built-in "queryBy*" query not reported because custom module not imported
153
+ import { render } from 'other-module'
154
+ queryByRole('button')
155
+ ` ,
156
+ } ,
157
+ {
158
+ settings : {
159
+ 'testing-library/filename-pattern' : 'testing-library\\.js' ,
160
+ } ,
161
+ code : `
162
+ // case: built-in "getBy*" query not reported because custom filename doesn't match
163
+ getByRole('button')
164
+ ` ,
165
+ } ,
166
+ {
167
+ settings : {
168
+ 'testing-library/filename-pattern' : 'testing-library\\.js' ,
169
+ } ,
170
+ code : `
171
+ // case: built-in "queryBy*" query not reported because custom filename doesn't match
172
+ queryByRole('button')
173
+ ` ,
174
+ } ,
92
175
] ,
93
176
invalid : [
94
177
// Test Cases for Imports & Filename
@@ -260,5 +343,135 @@ ruleTester.run(RULE_NAME, rule, {
260
343
` ,
261
344
errors : [ { line : 3 , column : 7 , messageId : 'fakeError' } ] ,
262
345
} ,
346
+
347
+ // Test Cases for all settings mixed
348
+ {
349
+ settings : {
350
+ 'testing-library/module' : 'test-utils' ,
351
+ 'testing-library/filename-pattern' : 'testing-library\\.js' ,
352
+ } ,
353
+ filename : 'MyComponent.testing-library.js' ,
354
+ code : `
355
+ // case: matching all custom settings
356
+ import { render } from 'test-utils'
357
+ import { somethingElse } from 'another-module'
358
+ const foo = require('bar')
359
+
360
+ const utils = render();
361
+ ` ,
362
+ errors : [ { line : 7 , column : 21 , messageId : 'fakeError' } ] ,
363
+ } ,
364
+
365
+ // Test Cases for Queries and Aggressive Queries Reporting
366
+ {
367
+ code : `
368
+ // case: built-in "getBy*" query reported without import (aggressive reporting)
369
+ getByRole('button')
370
+ ` ,
371
+ errors : [ { line : 3 , column : 7 , messageId : 'getByError' } ] ,
372
+ } ,
373
+ {
374
+ code : `
375
+ // case: built-in "queryBy*" query reported without import (aggressive reporting)
376
+ queryByRole('button')
377
+ ` ,
378
+ errors : [ { line : 3 , column : 7 , messageId : 'queryByError' } ] ,
379
+ } ,
380
+ {
381
+ filename : 'MyComponent.spec.js' ,
382
+ code : `
383
+ // case: custom "getBy*" query reported without import (aggressive reporting)
384
+ getByIcon('search')
385
+ ` ,
386
+ errors : [ { line : 3 , column : 7 , messageId : 'getByError' } ] ,
387
+ } ,
388
+ {
389
+ code : `
390
+ // case: custom "queryBy*" query reported without import (aggressive reporting)
391
+ queryByIcon('search')
392
+ ` ,
393
+ errors : [ { line : 3 , column : 7 , messageId : 'queryByError' } ] ,
394
+ } ,
395
+ {
396
+ settings : {
397
+ 'testing-library/module' : 'test-utils' ,
398
+ } ,
399
+ code : `
400
+ // case: built-in "getBy*" query reported with custom module + Testing Library package import
401
+ import { render } from '@testing-library/react'
402
+ getByRole('button')
403
+ ` ,
404
+ errors : [ { line : 4 , column : 7 , messageId : 'getByError' } ] ,
405
+ } ,
406
+ {
407
+ filename : 'MyComponent.spec.js' ,
408
+ code : `
409
+ // case: built-in "queryBy*" query reported with custom module + Testing Library package import
410
+ import { render } from '@testing-library/framework'
411
+ queryByRole('button')
412
+ ` ,
413
+ errors : [ { line : 4 , column : 7 , messageId : 'queryByError' } ] ,
414
+ } ,
415
+ {
416
+ settings : {
417
+ 'testing-library/module' : 'test-utils' ,
418
+ } ,
419
+ code : `
420
+ // case: built-in "getBy*" query reported with custom module + custom module import
421
+ import { render } from 'test-utils'
422
+ getByRole('button')
423
+ ` ,
424
+ errors : [ { line : 4 , column : 7 , messageId : 'getByError' } ] ,
425
+ } ,
426
+ {
427
+ filename : 'MyComponent.spec.js' ,
428
+ code : `
429
+ // case: built-in "queryBy*" query reported with custom module + custom module import
430
+ import { render } from 'test-utils'
431
+ queryByRole('button')
432
+ ` ,
433
+ errors : [ { line : 4 , column : 7 , messageId : 'queryByError' } ] ,
434
+ } ,
435
+
436
+ {
437
+ settings : {
438
+ 'testing-library/module' : 'test-utils' ,
439
+ } ,
440
+ code : `
441
+ // case: custom "getBy*" query reported with custom module + Testing Library package import
442
+ import { render } from '@testing-library/react'
443
+ getByIcon('search')
444
+ ` ,
445
+ errors : [ { line : 4 , column : 7 , messageId : 'getByError' } ] ,
446
+ } ,
447
+ {
448
+ filename : 'MyComponent.spec.js' ,
449
+ code : `
450
+ // case: custom "queryBy*" query reported with custom module + Testing Library package import
451
+ import { render } from '@testing-library/framework'
452
+ queryByIcon('search')
453
+ ` ,
454
+ errors : [ { line : 4 , column : 7 , messageId : 'queryByError' } ] ,
455
+ } ,
456
+ {
457
+ settings : {
458
+ 'testing-library/module' : 'test-utils' ,
459
+ } ,
460
+ code : `
461
+ // case: custom "getBy*" query reported with custom module + custom module import
462
+ import { render } from 'test-utils'
463
+ getByIcon('search')
464
+ ` ,
465
+ errors : [ { line : 4 , column : 7 , messageId : 'getByError' } ] ,
466
+ } ,
467
+ {
468
+ filename : 'MyComponent.spec.js' ,
469
+ code : `
470
+ // case: custom "queryBy*" query reported with custom module + custom module import
471
+ import { render } from 'test-utils'
472
+ queryByIcon('search')
473
+ ` ,
474
+ errors : [ { line : 4 , column : 7 , messageId : 'queryByError' } ] ,
475
+ } ,
263
476
] ,
264
477
} ) ;
0 commit comments