Created
August 3, 2012 21:03
-
-
Save kalebdf/3251500 to your computer and use it in GitHub Desktop.
Event triggered on helper for async Jasmine calls
This file contains 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
### | |
Stellar Module Test - Assumes jasmine is global | |
@author: Kaleb Fulgham | |
@license: MIT | |
### | |
define [ | |
'../specs/helpers/TestHelpers' | |
'modules/StellarModule' | |
], | |
(TestHelpers, StellarModule) -> | |
describe "StellarModule", -> | |
describe "ItemView", -> | |
it "should do foo bar baz with view", -> | |
itemView = new ItemView() | |
# Expect event 'render' to be triggered on the item view | |
TestHelpers.eventTriggeredOn itemView, 'render', => | |
$a = itemView.$('a') | |
expect($a.data('id')).toEqual @flight.id, 'Anchor data ID attribute' | |
# more expectations | |
# Call the async code | |
itemView.render() |
This file contains 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
### | |
TestHelpers | |
@author: Kaleb Fulgham | |
@license: MIT | |
### | |
define [], -> | |
TestHelpers = | |
eventTriggeredOn: (caller, eventName, callback) -> | |
### | |
Wait for the event to be triggered and execute the callback once done. | |
### | |
spy = spyOn(caller, 'trigger') | |
waitsFor -> | |
result = false | |
if spy.callCount > 0 | |
for callArgs in spy.argsForCall | |
if callArgs[0] == eventName | |
result = true | |
break | |
result | |
, "Async call to trigger event [#{eventName}] never occurred", 1000 | |
runs -> | |
callback() | |
TestHelpers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment