Skip to content

Commit

Permalink
Improve fill_in_with_force spec helper
Browse files Browse the repository at this point in the history
At the moment, after the input is filled with value=, the change
event is not fired.

If we had change listeners on that input they will not be executed.

For example we have a .ccType hidden field that is filled with the
type of the card added and this did remain empty since the backbone
view that was responsible to update it after the card number was
added did not get any trigger.
  • Loading branch information
kennyadsl committed Apr 4, 2019
1 parent 00c9b02 commit 841ba45
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/lib/spree/testing_support/capybara_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ def eventually_fill_in(field, options = {})
def fill_in_with_force(locator, with:)
if Capybara.current_driver == Capybara.javascript_driver
field_id = find_field(locator)[:id]
page.execute_script "document.getElementById('#{field_id}').value = '#{with}';"
page.execute_script <<-JS
var field = document.getElementById('#{field_id}');
field.value = '#{with}';
var event = new Event('change', { bubbles: true });
field.dispatchEvent(event);
JS
else
fill_in locator, with: with
end
Expand Down

0 comments on commit 841ba45

Please sign in to comment.