Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/rules/prefer-explicit-assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,17 @@ export default createTestingLibraryRule<Options, MessageIds>({
const expectCallNode = findClosestCallNode(node, 'expect');
if (!expectCallNode) return;

const expectStatement =
expectCallNode.parent as TSESTree.MemberExpression;
const property = expectStatement.property as TSESTree.Identifier;
const expectStatement = expectCallNode.parent;
if (!isMemberExpression(expectStatement)) {
return;
}

const property = expectStatement.property;

if (!ASTUtils.isIdentifier(property)) {
return;
}

let matcher = property.name;
let isNegatedMatcher = false;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@typescript-eslint/experimental-utils": "^4.30.0"
},
"devDependencies": {
"@babel/eslint-plugin": "^7.14.5",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@types/jest": "^27.0.1",
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/prefer-explicit-assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ ruleTester.run(RULE_NAME, rule, {
},
],
})),
{
// https://github.com/testing-library/eslint-plugin-testing-library/issues/475
code: `
// incomplete expect statement should be ignored
expect('something');
expect(getByText('foo'));
`,
options: [
{
assertion: 'toBeInTheDocument',
},
],
},
],
invalid: [
...COMBINED_QUERIES_METHODS.map(
Expand Down