Last active
August 29, 2015 13:58
-
-
Save suranyami/9965397 to your computer and use it in GitHub Desktop.
The following are the same specs (taken from here: http://jweden.tumblr.com/post/66999796589/async-testing-in-jasmine-2-0 ), working one in Javascript, the other, converted to Coffeescript (with js2coffee). The JS passes, the Coffeescript fails.
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 "Asynchronous specs", -> | |
funcRunInBackground = -> | |
value = 1 | |
return | |
wrapFuncRunInBackground = (done) -> | |
# setup for simmulating the async operation, a function run in the background | |
setTimeout (-> | |
funcRunInBackground() | |
done() | |
return | |
), 3000 | |
return | |
value = 0 | |
beforeEach (done) -> | |
wrapFuncRunInBackground done | |
console.log "wrap function returns immediately but value = 1 is set 3 seconds later. value is still " + value | |
return | |
it "should support async execution of test preparation", -> | |
expect(value).toBeGreaterThan 0 | |
return | |
return |
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 "Asynchronous specs", -> | |
########################### | |
# This needs to go HERE. # | |
########################### | |
value = 0 | |
funcRunInBackground = -> | |
value = 1 | |
return | |
wrapFuncRunInBackground = (done) -> | |
# setup for simmulating the async operation, a function run in the background | |
setTimeout (-> | |
funcRunInBackground() | |
done() | |
return | |
), 3000 | |
return | |
beforeEach (done) -> | |
wrapFuncRunInBackground done | |
console.log "wrap function returns immediately but value = 1 is set 3 seconds later. value is still " + value | |
return | |
it "should support async execution of test preparation", -> | |
expect(value).toBeGreaterThan 0 | |
return | |
return |
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("Asynchronous specs", function() { | |
var value = 0; | |
function funcRunInBackground() { | |
value = 1; | |
}; | |
function wrapFuncRunInBackground(done) { | |
// setup for simmulating the async operation, a function run in the background | |
setTimeout(function() { | |
funcRunInBackground(); | |
done(); | |
}, 3000); | |
} | |
beforeEach(function(done) { | |
wrapFuncRunInBackground(done); | |
console.log("wrap function returns immediately but value = 1 is set 3 seconds later. value is still " + value); | |
}); | |
it("should support async execution of test preparation", function() { | |
expect(value).toBeGreaterThan(0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment