Skip to content

Instantly share code, notes, and snippets.

@nghiaht
Last active December 6, 2018 08:06
Show Gist options
  • Save nghiaht/0d0e328db5d3689b52ef1cf45f5875e2 to your computer and use it in GitHub Desktop.
Save nghiaht/0d0e328db5d3689b52ef1cf45f5875e2 to your computer and use it in GitHub Desktop.
Jest Enzyme: onChange for material-ui Select (SelectInput - react-admin)
const handleSubmit = sinon.spy();
const wrapper = mount(
<Provider store={store}>
<MyForm onSubmit={handleSubmit} />
</Provider>
);
// Assume MyForm having a platform select input whose name is "platform"
const elem = wrapper.find("Select[name='platform']");
elem.prop("onChange")("iOS"); // Get onChange and call directly instead of the traditional elem.simulate("change", {target: {value: "iOS"}}) for <select> or <input>
expect(handleSubmit.getCall(0).args[0]).toMatchObject({ platform: "iOS" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment