@@ -9,6 +9,7 @@ const SUPPORTED_TESTING_FRAMEWORKS = [
99 '@testing-library/react' ,
1010 '@testing-library/vue' ,
1111 '@marko/testing-library' ,
12+ 'shadow-dom-testing-library' ,
1213] ;
1314
1415const QUERIES = [
@@ -20,6 +21,47 @@ const QUERIES = [
2021 'findAllByTestId' ,
2122] ;
2223
24+ const createInvalidTestCase = ( framework : string , query : string ) => {
25+ return [
26+ {
27+ code : `
28+ import { render } from '${ framework } ';
29+
30+ test('test', async () => {
31+ const { ${ query } } = render(<MyComponent />);
32+
33+ expect(${ query } ('my-test-id')).toBeInTheDocument();
34+ });
35+ ` ,
36+ errors : [
37+ {
38+ messageId : 'noTestIdQueries' ,
39+ line : 7 ,
40+ column : 14 ,
41+ } ,
42+ ] ,
43+ } ,
44+ {
45+ code : `
46+ import { render, screen } from '${ framework } ';
47+
48+ test('test', async () => {
49+ render(<MyComponent />);
50+
51+ expect(screen.${ query } ('my-test-id')).toBeInTheDocument();
52+ });
53+ ` ,
54+ errors : [
55+ {
56+ messageId : 'noTestIdQueries' ,
57+ line : 7 ,
58+ column : 14 ,
59+ } ,
60+ ] ,
61+ } ,
62+ ] as const ;
63+ } ;
64+
2365ruleTester . run ( rule . name , rule , {
2466 valid : [
2567 `
@@ -43,44 +85,22 @@ ruleTester.run(rule.name, rule, {
4385 ` ,
4486 ] ,
4587
46- invalid : SUPPORTED_TESTING_FRAMEWORKS . flatMap ( ( framework ) =>
47- QUERIES . flatMap ( ( query ) => [
48- {
49- code : `
50- import { render } from '${ framework } ';
51-
52- test('test', async () => {
53- const { ${ query } } = render(<MyComponent />);
54-
55- expect(${ query } ('my-test-id')).toBeInTheDocument();
56- });
57- ` ,
58- errors : [
59- {
60- messageId : 'noTestIdQueries' ,
61- line : 7 ,
62- column : 14 ,
63- } ,
64- ] ,
65- } ,
66- {
67- code : `
68- import { render, screen } from '${ framework } ';
69-
70- test('test', async () => {
71- render(<MyComponent />);
72-
73- expect(screen.${ query } ('my-test-id')).toBeInTheDocument();
74- });
75- ` ,
76- errors : [
77- {
78- messageId : 'noTestIdQueries' ,
79- line : 7 ,
80- column : 14 ,
81- } ,
82- ] ,
83- } ,
84- ] )
85- ) ,
88+ invalid : [
89+ ...SUPPORTED_TESTING_FRAMEWORKS . flatMap ( ( framework ) =>
90+ QUERIES . flatMap ( ( query ) => createInvalidTestCase ( framework , query ) )
91+ ) ,
92+ // special cases for shadow-dom-testing-library
93+ ...[
94+ 'ByShadowLabelText' ,
95+ 'ByShadowPlaceholderText' ,
96+ 'ByShadowText' ,
97+ 'ByShadowAltText' ,
98+ 'ByShadowTitle' ,
99+ 'ByShadowDisplayValue' ,
100+ 'ByShadowRole' ,
101+ 'ByShadowTestId' ,
102+ ] . flatMap ( ( query ) =>
103+ createInvalidTestCase ( 'shadow-dom-testing-library' , query )
104+ ) ,
105+ ] ,
86106} ) ;
0 commit comments