Skip to content

Instantly share code, notes, and snippets.

@oviava
Last active September 18, 2016 08:58
Show Gist options
  • Save oviava/fd0d8bf2073d0ec7635511f3b8978a67 to your computer and use it in GitHub Desktop.
Save oviava/fd0d8bf2073d0ec7635511f3b8978a67 to your computer and use it in GitHub Desktop.
class Input extends Component {
constructor() {
this.state = {
value: 0,
isValid: true,
};
}
changeHandler = (event) => {
// do stuff
}
render {
return <input onChange={this.changeHandler}/>
}
}
// test
() => {
const mockFunc = jest.fn();
Input.prototype.changeHandler = mockFunc;
const comp = mount(<Input />);
comp.find('input').simulate('change', { target: { value: 99 }});
expect(mockFunc).toBeCalled();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment