#How to test styles of component?

4 messages · Page 1 of 1 (latest)

jovial pond
#

I'm trying to test if a button's background color changes when clicked.
I have this code snippet:

const btn = screen.getByTestId("btn");
fireEvent.click(btn);

const btnStyles = getComputedStyle(btn);
expect(btnStyles.backgroundColor).toBe(mainColor);

Result:

Expected: "#000"
Received: "ButtonFace"
spark saffron
jovial pond
spark saffron