Skip to content

Instantly share code, notes, and snippets.

@cod3beat
Created October 25, 2013 03:50
Show Gist options
  • Save cod3beat/7149211 to your computer and use it in GitHub Desktop.
Save cod3beat/7149211 to your computer and use it in GitHub Desktop.
Memasang spy pada event handler pada Backbone
var ContohCollection = Backbone.Collection.extend({
// ....
initialize: function() {
this.model.on("something", this.onSomething, this);
},
onSomething: function() {
}
// ....
});
describe("ContohCollection Event Handling", function() {
it("Should have called onSomething on something event", function() {
// pasang spy pada collection sebelum ia diinisiasi
spyOn(ContohCollection.prototype, "onSomething");
var contohCollection = new ContohCollection();
// logika lain
// test
model.trigger("something");
expect(contohCollection.onSomething).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment