I have 2 components for this task.First one is my wrapper component and the second one is component for buttons.
I am clicking one of the buttons of my button component and it changes state in my wrapper component.
Now how can i bring that whole action in Jest(Enzyme) environment?
it('should update state', () => {
const onButtonClickMock = jest.fn();
const wrapper = shallow(<MyComponent/>)
const buttons = shallow(<Colors onClick={onButtonClickMock} colors={['gray', 'black', 'white']}/>);
const d = buttons.find('div#buttons');
const b = d.find('button.btn');
b.at(1).simulate('click');//Pick first button from bunch and click
wrapper.update();
expect(onButtonClickMock).toHaveBeenCalledTimes(1);//This works
expect(component2.state(['selection'])).toBe(1);
})
Aucun commentaire:
Enregistrer un commentaire