Skip to content

Instantly share code, notes, and snippets.

@twasink
Last active August 29, 2015 14:08
Show Gist options
  • Save twasink/dc68f2f8884e8c77b221 to your computer and use it in GitHub Desktop.
Save twasink/dc68f2f8884e8c77b221 to your computer and use it in GitHub Desktop.
Upgrade Jasmine 1.3 to Jasmine 2.0
Before
it("test stuff", function() {
...
waitsFor(function() {
return flag
}, "should set tthe flag, meaning its entered the callback", 150)
runs(function() {
controller.removeEvent(evt.id)
})
})
After:
it("test stuff", function(done() {
...
var intervalId = setInterval(function() {
console.log("Checking flag")
if (flag) {
controller.removeEvent(evt.id);
console.log("clearing interval")
clearInterval(intervalId)
done()
}
}, 150)
})
sed -i "" "s@andCallThrough@and.callThrough@g" `find */tests -name *Spec.js`
sed -i "" "s@andReturn@and.returnValue@g" `find */tests -name *Spec.js`
sed -i "" "s@mostRecentCall@calls.mostRecent()@g" `find */tests -name *Spec.js`
sed -i "" "s@andCallFake@and.callFake@g" `find */tests -name *Spec.js`
@twasink
Copy link
Author

twasink commented Oct 23, 2014

This upgrades most of the raw syntax of Jasmine tests to 2.0.

What this can't do is upgrade the asynchronous tests - that's too big a change, as it's not just a mapping, but a fundamental change (particularly the loss of run())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment