lundi 25 novembre 2019

Best way to test CSS styles in Jest

I have a component that has an image attribute with the component.

What is the best way to test the image attribute?

Test:

test("Menu has a background image called bg.png", () => {
  const menu = shallow(
    <Menu />
  );
  expect(menu.find('.menu-bg').prop('style')).toHaveProperty('background', "url('images/bg1.png')");
});

Menu Component:

export default class Menu extends React.Component {
  render() {
    return <div className="menu-bg" />;
  }
}

Style:

.menu-bg{
  background: url('images/bg1.png');

} 

I'm getting the current error:

   Matcher error: received value must not be null nor undefined

    Received has value: undefined

Aucun commentaire:

Enregistrer un commentaire