Created
August 29, 2014 16:25
-
-
Save richhollis/4185765d817b106c3aab to your computer and use it in GitHub Desktop.
Test backbone pubSub event triggers call their expected functions in jasmine spec
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
class BackbonePubSub | |
@verifyEvent: (klass, name, methodName, callMethod = "registerEvents") -> | |
match = false | |
oldFn = Backbone.pubSub.on # get existing pubSub.on method | |
class KlassNoConstructor extends klass # extend original class so we can disable constructor | |
constructor: -> # zap the constructor of the target class | |
instance = new KlassNoConstructor | |
Backbone.pubSub.on = (triggerName, method) -> | |
match = true if triggerName == name and method == instance[methodName] # are we triggering on the right method? | |
instance[callMethod]() # call the event registration method | |
Backbone.pubSub.on = oldFn # restore original Backbone pubSub.on method | |
match | |
window.BackbonePubSub = BackbonePubSub # export to global namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment