1
- import { type TSESLint } from '@typescript-eslint/utils ' ;
1
+ import { InvalidTestCase , ValidTestCase } from '@typescript-eslint/rule-tester ' ;
2
2
3
- import rule , { RULE_NAME , Options } from '../../../lib/rules/no-node-access' ;
3
+ import rule , {
4
+ RULE_NAME ,
5
+ Options ,
6
+ MessageIds ,
7
+ } from '../../../lib/rules/no-node-access' ;
8
+ import { EVENT_HANDLER_METHODS } from '../../../lib/utils' ;
4
9
import { createRuleTester } from '../test-utils' ;
5
10
6
11
const ruleTester = createRuleTester ( ) ;
7
12
8
- type ValidTestCase = TSESLint . ValidTestCase < Options > ;
13
+ type RuleValidTestCase = ValidTestCase < Options > ;
14
+ type RuleInvalidTestCase = InvalidTestCase < MessageIds , Options > ;
9
15
10
16
const SUPPORTED_TESTING_FRAMEWORKS = [
11
17
'@testing-library/angular' ,
@@ -15,7 +21,7 @@ const SUPPORTED_TESTING_FRAMEWORKS = [
15
21
] ;
16
22
17
23
ruleTester . run ( RULE_NAME , rule , {
18
- valid : SUPPORTED_TESTING_FRAMEWORKS . flatMap < ValidTestCase > (
24
+ valid : SUPPORTED_TESTING_FRAMEWORKS . flatMap < RuleValidTestCase > (
19
25
( testingFramework ) => [
20
26
{
21
27
code : `
@@ -100,7 +106,7 @@ ruleTester.run(RULE_NAME, rule, {
100
106
code : `/* related to issue #386 fix
101
107
* now all node accessing properties (listed in lib/utils/index.ts, in PROPERTIES_RETURNING_NODES)
102
108
* will not be reported by this rule because anything props.something won't be reported.
103
- */
109
+ */
104
110
import { screen } from '${ testingFramework } ';
105
111
function ComponentA(props) {
106
112
if (props.firstChild) {
@@ -142,17 +148,17 @@ ruleTester.run(RULE_NAME, rule, {
142
148
// Example from discussions in issue #386
143
149
code : `
144
150
import { render } from '${ testingFramework } ';
145
-
151
+
146
152
function Wrapper({ children }) {
147
153
// this should NOT be reported
148
154
if (children) {
149
155
// ...
150
156
}
151
-
157
+
152
158
// this should NOT be reported
153
159
return <div className="wrapper-class">{children}</div>
154
160
};
155
-
161
+
156
162
render(<Wrapper><SomeComponent /></Wrapper>);
157
163
expect(screen.getByText('SomeComponent')).toBeInTheDocument();
158
164
` ,
@@ -395,5 +401,24 @@ ruleTester.run(RULE_NAME, rule, {
395
401
} ,
396
402
] ,
397
403
} ,
404
+ ...EVENT_HANDLER_METHODS . map < RuleInvalidTestCase > ( ( method ) => ( {
405
+ code : `
406
+ import { screen } from '${ testingFramework } ';
407
+
408
+ const button = document.getElementById('submit-btn').${ method } ();
409
+ ` ,
410
+ errors : [
411
+ {
412
+ line : 4 ,
413
+ column : 33 ,
414
+ messageId : 'noNodeAccess' ,
415
+ } ,
416
+ {
417
+ line : 4 ,
418
+ column : 62 ,
419
+ messageId : 'noNodeAccess' ,
420
+ } ,
421
+ ] ,
422
+ } ) ) ,
398
423
] ) ,
399
424
} ) ;
0 commit comments