I have a component named AddEditVehicle which renders when the route is /vehicle/:vehicleId/edit.
I need to test the React lifecycles of this component. So I have used Enzyme mount to render my component in the unit test in the following way.
beforeEach(async () => {
wrapper = await mount(
<BrowserRouter>
<Provider store={store}>
<AddEditVehicle match={{ params: { vehicleId } }} />
</Provider>
</BrowserRouter>
);
await wrapper.update();
});
this wrapper fails to pass the required params making following specs to fail.
it("expect `isEditMode` value to set", () => {
const componentState = wrapper.find("AddEditVehicle").instance().state;
expect(componentState.isEditMode).toEqual(true);
});
Versions :
- react ^16.4.2
- react-router ^4.3.1
- jest ^23.5.0
- enzyme ^3.4.4
<MemoryRouter initialEntries={["/vehicle/2/edit"]} initialIndex={0}>, this is the console output when a print the match props in console{ path: '/', url: '/', params: {}, isExact: false}- Satyakiexpect(wrapper.state().isEditMode).toBeTruthy()- yohaizidat the URL. and setting the state variable toedit modetrue. So, I need to have access onidas well as the state. In the present scenario, state does not reflect the correct edit state as it's unable to check theidof url - Satyaki