Skip to content

Commit

Permalink
[Tests] no-static-element-interactions: add passing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
V2dha authored and ljharb committed Jul 7, 2022
1 parent 38405ad commit e7d405d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions __tests__/src/rules/no-static-element-interactions-test.js
Expand Up @@ -429,11 +429,26 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
// Expressions should pass in recommended mode
{ code: '<div role={ROLE_BUTTON} onClick={() => {}} />;' },
{ code: '<div {...this.props} role={this.props.role} onKeyPress={e => this.handleKeyPress(e)}>{this.props.children}</div>' },
// Cases for allowExpressionValues set to true
{
code: '<div role={BUTTON} onClick={() => {}} />;',
options: [{ allowExpressionValues: true }],
},
// Specific case for ternary operator with literals on both side
{
code: '<div role={isButton ? "button" : "link"} onClick={() => {}} />;',
options: [{ allowExpressionValues: true }],
},
{
code: '<div role={isButton ? "button" : LINK} onClick={() => {}} />;',
options: [{ allowExpressionValues: true }],
errors: [expectedError],
},
{
code: '<div role={isButton ? BUTTON : LINK} onClick={() => {}} />;',
options: [{ allowExpressionValues: true }],
errors: [expectedError],
},
)
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
Expand Down Expand Up @@ -470,6 +485,12 @@ ruleTester.run(`${ruleName}:strict`, rule, {
// Expressions should fail in strict mode
{ code: '<div role={ROLE_BUTTON} onClick={() => {}} />;', errors: [expectedError] },
{ code: '<div {...this.props} role={this.props.role} onKeyPress={e => this.handleKeyPress(e)}>{this.props.children}</div>', errors: [expectedError] },
// Cases for allowExpressionValues set to false
{
code: '<div role={BUTTON} onClick={() => {}} />;',
options: [{ allowExpressionValues: false }],
errors: [expectedError],
},
// Specific case for ternary operator with literals on both side
{
code: '<div role={isButton ? "button" : "link"} onClick={() => {}} />;',
Expand Down

0 comments on commit e7d405d

Please sign in to comment.