Skip to content

Commit e7d405d

Browse files
V2dhaljharb
authored andcommittedJul 7, 2022
[Tests] no-static-element-interactions: add passing test cases
1 parent 38405ad commit e7d405d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎__tests__/src/rules/no-static-element-interactions-test.js

+21
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,26 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
429429
// Expressions should pass in recommended mode
430430
{ code: '<div role={ROLE_BUTTON} onClick={() => {}} />;' },
431431
{ code: '<div {...this.props} role={this.props.role} onKeyPress={e => this.handleKeyPress(e)}>{this.props.children}</div>' },
432+
// Cases for allowExpressionValues set to true
433+
{
434+
code: '<div role={BUTTON} onClick={() => {}} />;',
435+
options: [{ allowExpressionValues: true }],
436+
},
432437
// Specific case for ternary operator with literals on both side
433438
{
434439
code: '<div role={isButton ? "button" : "link"} onClick={() => {}} />;',
435440
options: [{ allowExpressionValues: true }],
436441
},
442+
{
443+
code: '<div role={isButton ? "button" : LINK} onClick={() => {}} />;',
444+
options: [{ allowExpressionValues: true }],
445+
errors: [expectedError],
446+
},
447+
{
448+
code: '<div role={isButton ? BUTTON : LINK} onClick={() => {}} />;',
449+
options: [{ allowExpressionValues: true }],
450+
errors: [expectedError],
451+
},
437452
)
438453
.map(ruleOptionsMapperFactory(recommendedOptions))
439454
.map(parserOptionsMapper),
@@ -470,6 +485,12 @@ ruleTester.run(`${ruleName}:strict`, rule, {
470485
// Expressions should fail in strict mode
471486
{ code: '<div role={ROLE_BUTTON} onClick={() => {}} />;', errors: [expectedError] },
472487
{ code: '<div {...this.props} role={this.props.role} onKeyPress={e => this.handleKeyPress(e)}>{this.props.children}</div>', errors: [expectedError] },
488+
// Cases for allowExpressionValues set to false
489+
{
490+
code: '<div role={BUTTON} onClick={() => {}} />;',
491+
options: [{ allowExpressionValues: false }],
492+
errors: [expectedError],
493+
},
473494
// Specific case for ternary operator with literals on both side
474495
{
475496
code: '<div role={isButton ? "button" : "link"} onClick={() => {}} />;',

0 commit comments

Comments
 (0)
Please sign in to comment.