Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
JavaScript
<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!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900