Skip to content

Commit 5952362

Browse files
committed
fix(prefer-explicit-assert): avoid raising error on destructuring
1 parent 629a7c1 commit 5952362

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/rules/prefer-explicit-assert.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const isDeclared = node => node.parent.type === 'VariableDeclarator';
2424
const isReturnedByReturnStatement = node =>
2525
node.parent.type === 'ReturnStatement';
2626

27+
const isInDestructuringStatement = node =>
28+
(node.parent.type === 'Property' &&
29+
node.parent.parent.type === 'ObjectPattern') ||
30+
(node.parent.type === 'ArrayPattern' &&
31+
node.parent.parent.type === 'VariableDeclarator');
32+
2733
module.exports = {
2834
meta: {
2935
type: 'suggestion',
@@ -63,6 +69,7 @@ module.exports = {
6369

6470
if (
6571
isValidQuery(node, customQueryNames) &&
72+
!isInDestructuringStatement(node) &&
6673
!isDirectlyCalledByFunction(callExpressionNode) &&
6774
!isReturnedByArrowFunctionExpression(callExpressionNode) &&
6875
!isDeclared(callExpressionNode) &&

tests/lib/rules/prefer-explicit-assert.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ ruleTester.run('prefer-explicit-assert', rule, {
5050
{
5151
code: `getByIcon('foo')`, // custom `getBy` query not extended through options
5252
},
53+
{
54+
code: `const { getByText } = render()`,
55+
},
56+
{
57+
code: `it('test', () => { const { getByText } = render() })`,
58+
},
59+
{
60+
code: `it('test', () => { const [ getByText ] = render() })`,
61+
},
5362
],
5463

5564
invalid: [

0 commit comments

Comments
 (0)