Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test styles triggered by mouse over events

I have a button that displays different styles when mouse moves over it:

background-color: green;
&:hover {
  background-color: red;
}

Here is my test:

fireEvent.mouseOver(button);

expect(button).toHaveStyle(`
  background-color: red;
`);

However, the test complained that the background color is green instead of red. I tried fireEvent.mouseEnter before calling mouseOver. Didn't make any difference. What did I miss?

like image 728
doodoofish Avatar asked Sep 18 '18 00:09

doodoofish


1 Answers

You need to wait for the event to be fired and the style to be applied. You can try

fireEvent.mouseOver(button);

expect(await button).toHaveStyle(`
  background-color: red;
`);
like image 167
mayank1513 Avatar answered Oct 02 '22 12:10

mayank1513