Skip to content

Commit e2fd714

Browse files
committed
Add test on condition + fix broken unit-test
1 parent 7a9ac14 commit e2fd714

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/rules/jsx-no-bind.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ module.exports = {
8484
} else if (
8585
nodeType === 'ConditionalExpression'
8686
) {
87-
return getNodeViolationType(node.consequent) | getNodeViolationType(node.alternate);
87+
return getNodeViolationType(node.test) ||
88+
getNodeViolationType(node.consequent) ||
89+
getNodeViolationType(node.alternate);
8890
} else if (
8991
!configuration.allowArrowFunctions &&
9092
nodeType === 'ArrowFunctionExpression'

tests/lib/rules/jsx-no-bind.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ ruleTester.run('jsx-no-bind', rule, {
401401
code: `
402402
const foo = {
403403
render: ({onClick}) => (
404-
<div onClick={(true) ? onClick.bind(this) : onClick.bind(this)}>Hello</div>
404+
<div onClick={(returningBoolean()) ? onClick.bind(this) : onClick.bind(this)}>Hello</div>
405405
)
406406
};
407407
`,
@@ -411,7 +411,7 @@ ruleTester.run('jsx-no-bind', rule, {
411411
code: `
412412
const foo = {
413413
render: ({onClick}) => (
414-
<div onClick={(true) ? onClick.bind(this) : handleClick()}>Hello</div>
414+
<div onClick={(returningBoolean()) ? onClick.bind(this) : handleClick()}>Hello</div>
415415
)
416416
};
417417
`,
@@ -421,12 +421,23 @@ ruleTester.run('jsx-no-bind', rule, {
421421
code: `
422422
const foo = {
423423
render: ({onClick}) => (
424-
<div onClick={(true) ? handleClick() : onClick.bind(this)}>Hello</div>
424+
<div onClick={(returningBoolean()) ? handleClick() : this.onClick.bind(this)}>Hello</div>
425425
)
426426
};
427427
`,
428428
errors: [{message: 'JSX props should not use .bind()'}]
429429
},
430+
{
431+
code: `
432+
const foo = {
433+
render: ({onClick}) => (
434+
<div onClick={returningBoolean.bind(this) ? handleClick() : onClick()}>Hello</div>
435+
)
436+
};
437+
`,
438+
errors: [{message: 'JSX props should not use .bind()'}]
439+
},
440+
430441

431442
// Arrow functions
432443
{

0 commit comments

Comments
 (0)