1- import { type TSESLint } from '@typescript-eslint/utils ' ;
1+ import { InvalidTestCase , ValidTestCase } from '@typescript-eslint/rule-tester ' ;
22
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' ;
49import { createRuleTester } from '../test-utils' ;
510
611const ruleTester = createRuleTester ( ) ;
712
8- type ValidTestCase = TSESLint . ValidTestCase < Options > ;
13+ type RuleValidTestCase = ValidTestCase < Options > ;
14+ type RuleInvalidTestCase = InvalidTestCase < MessageIds , Options > ;
915
1016const SUPPORTED_TESTING_FRAMEWORKS = [
1117 '@testing-library/angular' ,
@@ -15,7 +21,7 @@ const SUPPORTED_TESTING_FRAMEWORKS = [
1521] ;
1622
1723ruleTester . run ( RULE_NAME , rule , {
18- valid : SUPPORTED_TESTING_FRAMEWORKS . flatMap < ValidTestCase > (
24+ valid : SUPPORTED_TESTING_FRAMEWORKS . flatMap < RuleValidTestCase > (
1925 ( testingFramework ) => [
2026 {
2127 code : `
@@ -100,7 +106,7 @@ ruleTester.run(RULE_NAME, rule, {
100106 code : `/* related to issue #386 fix
101107 * now all node accessing properties (listed in lib/utils/index.ts, in PROPERTIES_RETURNING_NODES)
102108 * will not be reported by this rule because anything props.something won't be reported.
103- */
109+ */
104110 import { screen } from '${ testingFramework } ';
105111 function ComponentA(props) {
106112 if (props.firstChild) {
@@ -142,17 +148,17 @@ ruleTester.run(RULE_NAME, rule, {
142148 // Example from discussions in issue #386
143149 code : `
144150 import { render } from '${ testingFramework } ';
145-
151+
146152 function Wrapper({ children }) {
147153 // this should NOT be reported
148154 if (children) {
149155 // ...
150156 }
151-
157+
152158 // this should NOT be reported
153159 return <div className="wrapper-class">{children}</div>
154160 };
155-
161+
156162 render(<Wrapper><SomeComponent /></Wrapper>);
157163 expect(screen.getByText('SomeComponent')).toBeInTheDocument();
158164 ` ,
@@ -395,5 +401,24 @@ ruleTester.run(RULE_NAME, rule, {
395401 } ,
396402 ] ,
397403 } ,
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+ } ) ) ,
398423 ] ) ,
399424} ) ;
0 commit comments