Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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).

like image 950
reectrix Avatar asked Aug 15 '16 19:08

reectrix


People also ask

When would an Onblur event occurs?

The onblur attribute fires the moment that the element loses focus. Onblur is most often used with form validation code (e.g. when the user leaves a form field).

What is Onblur event in react?

The onBlur event handler is called when focus has left the element (or left some element inside of it). For example, it's called when the user clicks outside of a focused text input. function Example() { return ( <input onBlur={(e) => { console.

What is blur method in angular?

A blur event fires when an element has lost focus. Note: As the blur event is executed synchronously also during DOM manipulations (e.g. removing a focussed input), AngularJS executes the expression using scope.


1 Answers

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.

like image 122
boldnik Avatar answered Sep 23 '22 16:09

boldnik