Skip to content

Commit 72f2890

Browse files
committed
Allow fill_in to work with reactjs
React overrides the native setter of html input elements, so it doesn't fire change events when the value is changed. Because of that, for those input types where capybara uses javascript to change the value, change events are not fired as you'd expect when using react. I've updated the code to use the un-overridden value setter instead as recommended here: https://stackoverflow.com/a/46012210 I believe this shouldn't adversely affect apps using other javascript frameworks or no frameworks at all
1 parent f857a99 commit 72f2890

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/capybara/selenium/node.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ def update_value_js(value)
353353
arguments[0].focus();
354354
}
355355
if (arguments[0].value != arguments[1]) {
356-
arguments[0].value = arguments[1]
356+
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(arguments[0].__proto__, "value").set;
357+
nativeInputValueSetter.call(arguments[0], arguments[1]);
358+
357359
arguments[0].dispatchEvent(new InputEvent('input'));
358360
arguments[0].dispatchEvent(new Event('change', { bubbles: true }));
359361
}

0 commit comments

Comments
 (0)