0

I have a parent which sets a style for the children when it is focused. Which works perfectly when I compile my react project.

I am using react emotion, but it does not matter, because in the end I have usual css.

  const parentStyle = css`
    :focus {
      #child {
        border: 2px solid blue !important;
      }
    }
  `;

I want to get from within child element the border style.

I am using jest to test this and I tried something like this.

parent.simulate('focus');
const childNode = wrapper.find("#child");
const computedStyles = window.getComputedStyle(childNode);
expect(computedStyles.getPropertyValue('border')).toBe('2px solid blue');

So the expect is failing, it is not getting the border style.

AlexZvl
  • 2,092
  • 4
  • 18
  • 32

1 Answers1

0

Please try to use .element instead (if you still need the answer):

const computedStyles = window.getComputedStyle(childNode.element);

Milky Man
  • 1
  • 1