mercredi 29 juillet 2020

How to test CSS property value with Jest Enzyme in React

I have a component that changes style depending on window size via media query in the CSS, however I can't seem to test it within React's Jest Enzyme framework.

I am currently doing this:

it('my test', () => {
  const myEl = wrapperEmail.find('a').at(1);
  expect(myEl.style).toHaveProperty('text-decoration', 'none');
});

However I get the error:

expect(received).toHaveProperty(path, value)

Matcher error: received value must not be null nor undefined

Received has value: undefined

I have also tried the old fashioned method:

const myEl = document.getElementsByTagName('a')[1];
expect(myEl.style['text-decoration']).toEqual('none');

with the error:

TypeError: Cannot read property 'style' of undefined

Aucun commentaire:

Enregistrer un commentaire