Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't test customEvents #75

Closed
amk221 opened this issue Jul 7, 2015 · 8 comments
Closed

can't test customEvents #75

amk221 opened this issue Jul 7, 2015 · 8 comments

Comments

@amk221
Copy link
Contributor

amk221 commented Jul 7, 2015

We have these on our Application:

customEvents: {
    webkitAnimationEnd: 'animationEnd',
    msAnimationEnd: 'animationEnd',
    oAnimationEnd: 'animationEnd',
    animationend: 'animationEnd'
}

...and in a component integration test:

this.render('{{foo-bar}}')
this.$().trigger('click') // works
this.$().trigger('animationEnd') // doesn't work
@rwjblue
Copy link
Member

rwjblue commented Jul 7, 2015

We create and setup the EventDispatcher here for unit tests and here for integration tests but do not provide any custom settings.

Ember does that here as part of application boot, passing the customEvents hash that is specified on the Ember.Application instance.

@rwjblue
Copy link
Member

rwjblue commented Jul 7, 2015

The simplest solution is to allow the user to specify customEvents (instead of using {}). Something like:

moduleForComponent('foo-bar', {
  beforeEach() {
    this.customEvents = {
      webkitAnimationEnd: 'animationEnd'
      msAnimationEnd: 'animationEnd'
      oAnimationEnd: 'animationEnd'
      animationend: 'animationEnd'
    };
  }
});

Which would be used here like so:

context.dispatcher = Ember.EventDispatcher.create();
context.dispatcher.setup(context.customEvents || {}, '#ember-testing');

@rwjblue
Copy link
Member

rwjblue commented Jul 7, 2015

@ef4 / @dgeb - Would love your thoughts on the right API here...

@ef4
Copy link
Contributor

ef4 commented Jul 15, 2015

Ideally we should not require additional config. If you have custom events set up correctly in your app, they should Just Work in integration tests too.

We may need to refactor Application a little so that we can use just the customized event setup separately from booting a whole app instance.

@amk221
Copy link
Contributor Author

amk221 commented Sep 7, 2015

I'd like to contribute, but would need hand holding

@amk221
Copy link
Contributor Author

amk221 commented Feb 24, 2016

Anybody? it's been a while :|

@mitchlloyd
Copy link

Got some help from @rwjblue on this one today and wanted to share here:

It seems that a nicer (but currently undocumented solution) is to extend the EventDispatcher:

// inside of app/event_dispatcher.js
import Ember from 'ember';

export default Ember.EventDispatcher.extend({
  init() {
    this._super(...arguments);
    this.events.webkitAnimationEnd = 'animationEnd'
  }
});

This works and feels like a better solution since setting up custom events is unlikely to change based on the current environment.

The _ in the file name is surprising but currently needed. Also there could be a more intentional hook to let users edit the events.

@rwjblue
Copy link
Member

rwjblue commented May 26, 2016

Thanks for writing up the solution here. I think I'm going to close this issue now that the solution is documented, but I suspect we might still want to do some work in Ember to make this a bit more ergonomic. I'm happy to help someone spearhead an RFC on this, if they are interested in it...

@rwjblue rwjblue closed this as completed May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants