How to test decorated React component with shallow rendering

后端 未结 5 969
旧巷少年郎
旧巷少年郎 2020-12-15 19:45

I am following this tutorial: http://reactkungfu.com/2015/07/approaches-to-testing-react-components-an-overview/

Trying to learn how \"shallow rendering\" works.

5条回答
  •  一生所求
    2020-12-15 20:36

    Use Enzyme to test higher order / decorators with Shallow with a method called dive()

    Follow this link, to see how dive works

    https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/dive.md

    So you can shallow the component with higher order and then dive inside.

    In the above example :

    const wrapper=shallow()
    expect(wrapper.find("PlayerProfile").dive().find(".player-profile").length).toBe(1)
    

    Similarly you can access the properties and test it.

提交回复
热议问题