Does anyone have experience testing with Jest/Enzyme?
I need to write a test that renders the first value on selection and other parameter fields are hidden. This is an example of what my code looks like:
<ParameterFieldset
parameterName="reservoir_permeability"
parameterLabel="Reservoir permeability"
defaultValues={{
fixedValue: reservoirPermeability.fixedValue,
min: reservoirPermeability.min,
max: reservoirPermeability.max,
mean: reservoirPermeability.mean,
sd: reservoirPermeability.sd,
mode: reservoirPermeability.mode,
values: reservoirPermeability.values,
weights: reservoirPermeability.weights,
valid: reservoirPermeability.valid,
}}
/>
<ParameterFieldset
parameterName="reservoir_porosity"
parameterLabel="Reservoir porosity"
defaultValues={{
fixedValue: reservoirPorosity.fixedValue,
min: reservoirPorosity.min,
max: reservoirPorosity.max,
mean: reservoirPorosity.mean,
sd: reservoirPorosity.sd,
mode: reservoirPorosity.mode,
values: reservoirPorosity.values,
weights: reservoirPorosity.weights,
valid: reservoirPermeability.valid,
}}/>
So when reservoir_permeability fixed value is selected the min,max etc should be hidden. As well as the options for reservoir_porosity. Does that make sense?
What I have tried:
Heres what I have so far:
it('renders fixed value on reservour parmeability selection and other parameter fields are hidden', async () => {
const wrapper = mount(
<RecoilRoot>
<ReservoirTypeFieldset />
</RecoilRoot>
);
await act(async () => {
wrapper.find('select').at(0).prop('onChange')({
currentTarget: { value: 'reservoir_permeability' },
});
wrapper.mount();
wrapper.update();
});
expect(wrapper.find('fixedValue')).toHaveLength(1);
expect(wrapper.find(' min')).toHaveLength(1);
});
But I get this error:
expect(received).toHaveLength(expected)
Expected length: 1
Received length: 0
Received object: {}
Any help is much-appreciated thanks!