💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
This rule is an autofixable rule that encourages the use of toHaveValue over checking the value attribute.
This rule checks for usages of .value
or .toHaveAttribute("value")
.
The only valid use case is when using greater/less than
matchers since there isn't any equivalent use with toHaveValue
Examples of incorrect code for this rule:
expect(element).toHaveAttribute("value", "foo");
expect(element).toHaveProperty("value", "foo");
expect(element.value).toBe("foo");
expect(element.value).not.toEqual("foo");
expect(element.value).not.toStrictEqual("foo");
Examples of correct code for this rule:
expect(element).toHaveValue("foo");
expect(element.value).toBeGreaterThan(2);
expect(element.value).toBeLessThan(2);
If you don't care about using built in matchers for checking attributes on dom elements.