Skip to content

Commit e37070a

Browse files
committed
fix(prefer-in-document): don't crash on matchers that are not being called
1 parent 9b99529 commit e37070a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/__tests__/lib/rules/prefer-in-document.js

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ const valid = [
8888
`expect(screen.getAllByText("foo")).toHaveLength(getLength())`,
8989
`expect(screen.getAllByText("foo")).toBe(foo)`,
9090
`expect(screen.getAllByText("foo")).toEqual(foo)`,
91+
`
92+
const element = getByText('value')
93+
expect(element).toBeTruthy`,
94+
`
95+
const element = getByText('value')
96+
expect(element).toBe.truthy`,
97+
`
98+
const element = getByText('value')
99+
expect(element).toBeInTheDocument`,
91100
];
92101
const invalid = [
93102
invalidCase(

src/rules/prefer-in-document.js

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export const create = (context) => {
7171
negatedMatcher,
7272
expect,
7373
}) {
74+
if (matcherNode.parent.parent.type !== "CallExpression") {
75+
return;
76+
}
77+
7478
// only report on dom nodes which we can resolve to RTL queries.
7579
if (!queryNode || (!queryNode.name && !queryNode.property)) return;
7680

0 commit comments

Comments
 (0)