Calling setState () when using mocha + enzyme does not affect component state

When I use the setSate () method on a compiled component, the state is not set. The control takes state from the production code, not from the state assigned from the test. Find the code below.

const wrapper = mount(<BookFlight />
    wrapper.setState({ cabins: {
          fields: [
            {
              label: 'Economy',
              value: 'econ',
              name: 'cabin',
              type: 'radio'
            },
            {
              label: 'Business',
              value: 'business',
              name: 'cabin',
              type: 'radio'
            },
            {
              label: 'First',
              value: 'first',
              name: 'cabin',
              type: 'radio'
            }
          ]
        }})
        expect(wrapper.state().cabins.fields.length).toBe(3)
+4
source share

Source: https://habr.com/ru/post/1654005/


All Articles