How do you generate a blur or onBlur event in Enzyme?

reectrix picture reectrix · Aug 15, 2016 · Viewed 19.5k times · Source

I've tried:

input.simulate('blur');

and

input.simulate('onBlur');

None of these work. Is this even available in Enzyme (I'm using version 2.4.1).

Answer

boldnik picture boldnik · Nov 10, 2016

input.simulate('focus'), input.simulate('change') and input.simulate('blur') should work. Check if your input is actually a node declared as _wrapper.find('input') and exists. Secondly, there's another question similar to this one: Enzyme - How to access and set <input> value? And finally if you check the source code of the ReactWrapper component then you will find that it uses all events that React can recognize. So the error is somewhere in your code.