How to test style for a React component attribute with Enzyme

前端 未结 10 985
刺人心
刺人心 2020-12-09 07:21

I am trying to test a style attribute for a React component. What is the best way to get style params in the test?

At this moment, my best option is to test if the H

10条回答
  •  暖寄归人
    2020-12-09 07:55

    Slightly elaborating on others' answers:

    expect(component.find('#item-id').prop('style')).toHaveProperty('backgroundSize', '100%');
    

    This will check the style prop of #item-id. This prop is an object and here toHaveProperty matcher checks if this object contains backgroundSize property and if its value is 100%.

    This way other style properties are ignored.

提交回复
热议问题