diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 81bc8db..dec7f09 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -416,7 +416,8 @@ class Cuprite { options["button"] || 0, null ) } else if (EVENTS.FOCUS.indexOf(name) != -1) { - event = this.obtainEvent(name); + event = document.createEvent("FocusEvent"); + event.initEvent(name, true, true); } else if (EVENTS.FORM.indexOf(name) != -1) { event = this.obtainEvent(name); } else { diff --git a/spec/features/session_spec.rb b/spec/features/session_spec.rb index db0e640..bbcdbdd 100644 --- a/spec/features/session_spec.rb +++ b/spec/features/session_spec.rb @@ -200,11 +200,11 @@ end it "fires the focus event" do - expect(@session.find(:css, "#changes_on_focus").text).to eq("Focus") + expect(@session.find(:css, "#changes_on_focus").text).to eq("Focus (FocusEvent)") end it "fires the blur event" do - expect(@session.find(:css, "#changes_on_blur").text).to eq("Blur") + expect(@session.find(:css, "#changes_on_blur").text).to eq("Blur (FocusEvent)") end it "fires the keydown event before the value is updated" do diff --git a/spec/support/public/test.js b/spec/support/public/test.js index 7b11808..9bf8a10 100644 --- a/spec/support/public/test.js +++ b/spec/support/public/test.js @@ -28,10 +28,10 @@ $(function() { $("#changes_on_keypress").text(increment) }) .focus(function(event) { - $("#changes_on_focus").text("Focus") + $("#changes_on_focus").text(`Focus (${event.originalEvent.constructor.name})`) }) - .blur(function() { - $("#changes_on_blur").text("Blur") + .blur(function(event) { + $("#changes_on_blur").text(`Blur (${event.originalEvent.constructor.name})`) }) $("#browser")