File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { createRuleTester } from '../test-utils' ;
2
+ import rule , { RULE_NAME } from '../../../lib/rules/no-node-access' ;
3
+
4
+ const ruleTester = createRuleTester ( {
5
+ ecmaFeatures : {
6
+ jsx : true ,
7
+ } ,
8
+ } ) ;
9
+
10
+ ruleTester . run ( RULE_NAME , rule , {
11
+ valid : [
12
+ {
13
+ code : `
14
+ const buttonText = screen.getByText('submit');
15
+ ` ,
16
+ } ,
17
+ {
18
+ code : `
19
+ const obj = {
20
+ firstChild: <div>child</div>
21
+ }
22
+ obj.firstChild
23
+ ` ,
24
+ } ,
25
+ ] ,
26
+ invalid : [
27
+ {
28
+ code : `
29
+ function getExampleDOM() {
30
+ const container = document.createElement('div');
31
+ container.innerHTML = \`
32
+ <label for="username">Username</label>
33
+ <input id="username" />
34
+ <button>Print Username</button>
35
+ <label for="password">Password</label>
36
+ <input id="password" />
37
+ <button>Print password</button>
38
+ <button type="submit">Submit</button>
39
+ \`;
40
+ return container;
41
+ }
42
+ const exampleDOM = getExampleDOM();
43
+ const buttons = screen.getAllByRole(exampleDOM, 'button');
44
+ const buttonText = buttons[1].firstChild
45
+ ` ,
46
+ errors : [
47
+ {
48
+ messageId : 'noNodeAccess' ,
49
+ } ,
50
+ ] ,
51
+ } ,
52
+ ] ,
53
+ } ) ;
You can’t perform that action at this time.
0 commit comments