Unit testing: react context api with enzyme return an empty object

后端 未结 2 1168
粉色の甜心
粉色の甜心 2021-01-14 15:21

I am trying for the first time to use React context API to pass information from a main component to his grandchild component.

So first I have created a context

2条回答
  •  情深已故
    2021-01-14 16:10

    Enzyme context affects legacy React context, not modern context API. It should be mocked with:

    mount()
    

    And asserted with:

    expect(wrapper.find('h2').text()).toBe('Context value: 987');
    

提交回复
热议问题