Unit testing: Check component does not have style

Viewed 12

I have a component named Message and a property named focus. If focus is true, a style with outline: none will be added. I want to check the opposite case also, that if focus is false, the outline style will be not existed.

I write the test case like this, however the value return is same as focus="true" (always check it have outline style)

test("render component without focus", () => {
        const { container } = render(<Message focus={false} message={"Message"} />);
        expect(container.firstChild).not.toHaveStyleRule("outline", "none");
    });

Does anyone know what I am missing? Thank all

0 Answers
Related