Created
October 25, 2013 03:50
-
-
Save cod3beat/7149211 to your computer and use it in GitHub Desktop.
Memasang spy pada event handler pada Backbone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ContohCollection = Backbone.Collection.extend({ | |
// .... | |
initialize: function() { | |
this.model.on("something", this.onSomething, this); | |
}, | |
onSomething: function() { | |
} | |
// .... | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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