-
-
Save sleepynate/1715403 to your computer and use it in GitHub Desktop.
it("derps when using a space in an event name", function() { | |
var callback = jasmine.createSpy('-Custom Event Callback-'); | |
obj.bind('all', callback); | |
obj.trigger("foo bar"); | |
expect(callback.callCount).toBe(1); | |
expect(callback.mostRecentCall.args[0]).toBe('foo bar'); | |
}); |
I think it makes sense, the callback would be fired twice given 2 events are being triggered, I think the test just needs to be more explicit about that.
EXCEPT that on line 5, you used to be able to name a single event "foo bar"
Ah, so binding works with space-separated events but triggering is still a singular operation. That makes sense because arguments from .trigger are passed along to the function that was bound. Triggering two events at once doesn't seem like it would be something that would be frequently done and even if you wanted to you would have no way to determine which arguments were passed to the callback. (By convention backbone passes the model instance AND the changed attribute[singular] to the callback).
In the case of
person.bind("change:name change:location", callback);
the callback will fire two times and the arguments will contain the model and changed value of each field
ie:
callback(model, name);
callback(model, location);
Yea check out the expectation in larry's project: https://github.com/larrymyers/backbone-koans/blob/master/js/koans/aboutEvents.js#L66
Does this throw a syntax error or just have output different than what you expected? I was thinking for the example given on the backbone 0.9 changelog you could bind 2 model fields to change like they do, then do a model.set with those values and expect the callback was called.