bluerail / twitter-bootstrap-rails-confirm

Confirm dialogs using Twitter Bootstrap
https://bluerail.nl
MIT License
85 stars 34 forks source link

Problems with using event constructors #18

Closed kramerc closed 6 years ago

kramerc commented 10 years ago

Ever since commit 59bf1f91e81ad0dcba18a8c287465719f7448c19 was merged in, Capybara feature specs using either the capybara-webkit or Poltergeist drivers fail when testing confirmation dialogs powered by this gem. Debugging the failures, I found the following error that is tripping the specs:

ReferenceError: Can't find variable: MouseEvents

Correcting MouseEvents to MouseEvent presents another issue. While this resolves the above error in Firefox and Chrome, both Safari and the Capybara drivers give the following error:

TypeError: '[object MouseEventConstructor]' is not a constructor (evaluating 'new MouseEvent')

With Safari 6.0.5, switching MouseEvent to Event works as intended. With the Capybara drivers, however, they present a similar error as the one above with Event, thus leading me to assume they're working with older versions of JavaScriptCore. There is a related issue regarding this on the PhantomJS repo: ariya/phantomjs#11289

I would suggest either reverting the commit for now or changing MouseEvents to Event and add backwards compatibility while other browsers and WebKit test drivers catch up.

rvanlieshout commented 10 years ago

Hi Kramerc, Could you try the current version in master?

kramerc commented 10 years ago

The ReferenceError is no longer an issue but I am getting that TypeError with Capybara and Poltergeist. Changing new MouseEvent to new Event should fix the error.

rvanlieshout commented 10 years ago

Event also seems to work for me. Updated master :)

kramerc commented 10 years ago

Hmm, it seems I was under the false impression I had several days ago thinking that change would fix it as the tests still fail with Poltergeist and capybara-webkit drivers with a similar TypeError.

A try {...} catch {...} might work to have these driver implementations fall back to the older event initialization code. I am under the impression that the capybara-webkit driver and PhantomJS have some issues as I don't find this issue to be an actual issue with this gem.

rvanlieshout commented 10 years ago

It should only execute this if Event is defined. What line exactly raises this error?

kramerc commented 10 years ago

This is the exact error:

TypeError: '[object EventConstructor]' is not a constructor

The problem is that Event and MouseEvent are actually defined, just they're not being considered constructors. This is why if Event? passes.

kramerc commented 10 years ago

This seems to be an issue with QtWebKit, both of which capybara-webkit and PhantomJS use. A simple Qt web browser application produces the same problem.

rvanlieshout commented 10 years ago

Then i'll give that a spin soon

rvanlieshout commented 10 years ago

Hi Peter,

Some changes have been made to the master branch that might resolve the issue. I've not yet tested this using a Qt web browser yet though. Did you try the version in master?

Cheers,

Rene

Rene van Lieshout

rene.lico.nl | LinkedIn

Op 16 jan. 2014, om 23:49 heeft Peter Mouland notifications@github.com het volgende geschreven:

I was just wandering if this was still an issue?

I just bumped into the following error:

'[object EventConstructor]' is not a constructor (evaluating 'new Event(e)') when running the following code within my mocha spec:

event.emit(window,'resize'); which translates into this pretty standard cross browser event handler

function emit(el, eventName) { var event; if (document.createEvent) { event = new Event(eventName); el.dispatchEvent(event); } else { event = document.createEventObject(); el.fireEvent('on' + eventName, event); } } — Reply to this email directly or view it on GitHub.

peter-mouland commented 10 years ago

i haven't, no, just been using the released version that came with grunt-mocha.

owenbendavies commented 9 years ago

This appears to still be a problem for me: https://travis-ci.org/obduk/cms/builds/40487152

And this appears to fix it: https://github.com/obduk/twitter-bootstrap-rails-confirm/compare/bluerail:bootstrap3...fix_events

rvanlieshout commented 9 years ago

I don't mind the addition of the else element.trigger "click", but the if Event? is there for a reason. Does it produce any js error that isn't visible in the travis-ci output? I would prefer to tighten the conditions for the if Event?

rvanlieshout commented 6 years ago

I've never had any complaints about this issue anymore so closing it. Feel free to reopen if it's still relevant