Skip to content

Commit 4d41edc

Browse files
test(no-node-access): add first scenarios
1 parent 9ebf44e commit 4d41edc

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
});

0 commit comments

Comments
 (0)