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)
source
share