I use Enzyme , and we can use the sample component provided in the documentation as the basis for my question.
Suppose this <Foo/> component uses the <Link> component from ReactRouter, and so we need to wrap it in <MemoryRouter> for testing.
This is the problem.
it('puts the lotion in the basket', () => { const wrapper = mount( <MemoryRouter> <Foo /> </MemoryRouter> ) wrapper.state('name')
Thus, Iโm not quite sure how to access the state of the local component when using <MemoryRouter> .
Maybe I'm doing an ignorant test? Is trying to get / set the state of a component a bad practice when testing? I canโt imagine it, since Enzyme has methods for getting / setting the state of a component.
Just not sure how to access the internal components of the component, <MemoryRouter> in <MemoryRouter> .
Any help would be greatly appreciated!
react-router react-router-v4 jestjs enzyme
indiesquidge
source share