💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
Please describe the origin of the rule here.
This rule aims to prevent checking of the textContent
DOM node attribute in
tests and prefer toHaveTextContent
instead.
Examples of incorrect code for this rule:
expect(element.textContent).toBe("foo");
expect(container.firstChild.textContent).toBe("foo");
expect(getByText("foo").textContent).toBe("foo");
expect(screen.getByText("foo").textContent).toBe("foo");
expect(element.textContent).toEqual("foo");
expect(element.textContent).toContain("foo");
expect(element.textContent).not.toBe("foo");
expect(element.textContent).not.toContain("foo");
Examples of correct code for this rule:
expect(string).toBe("foo");
expect(element).toHaveTextContent("foo");
expect(container.lastNode).toBe("foo");
Don't use this rule if you don't care about the added readability and
improvements that toHaveTextContent
offers to your expects.