Skip to content

Commit 887a35c

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

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/rules/prefer-explicit-assert.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ 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+
2732
module.exports = {
2833
meta: {
2934
type: 'suggestion',
@@ -63,6 +68,7 @@ module.exports = {
6368

6469
if (
6570
isValidQuery(node, customQueryNames) &&
71+
!isInDestructuringStatement(node) &&
6672
!isDirectlyCalledByFunction(callExpressionNode) &&
6773
!isReturnedByArrowFunctionExpression(callExpressionNode) &&
6874
!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)