xolvio / rtd

DEPRECATED: The Test Runner for Meteor
164 stars 37 forks source link

fireEvent's strange behavior #165

Closed D-Ne0 closed 10 years ago

D-Ne0 commented 10 years ago

In my project I have defined template events in the following way:

Template.xyz.events = {
   'click .some-class': function () {}
};

When I call Template.xyz.fireEvent('click .some-class') in a spec it throws an error: "TypeError: 'undefined' is not a function (evaluating 'TemplateClass.prototype[templateName].eventMap[key]()')"

But If I define the events in the following way, the error is gone.

Template.xyz.events({
   'click .some-class': function () {}
});

What could be the reason for this behavior?

samhatoum commented 10 years ago

Hi

It's because the meteor stub defines events as a function, which then sets the events object inside the stub that the fire events relies on. I guess we could make fireEvent a little more intelligent in that it checks to see if the user specified the events object directly, vs using the method approach, and would then pull out the event accordingly. I'll keep this open so we can code that, but changing your code for now is going to be the quickest as we're working on porting the unit testing of RTD to velocity

samhatoum commented 10 years ago

closing here as won't fix in RTD