Last active
December 10, 2015 17:05
-
-
Save Nepoxx/2d37d3d405173f0f7736 to your computer and use it in GitHub Desktop.
testing module that uses bluebirdd
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("when navigating to a route", function() { | |
beforeEach(function() { | |
jasmine.Ajax.install(); | |
}); | |
afterEach(function() { | |
jasmine.Ajax.uninstall(); | |
}) | |
it("should have called the err function, making 'errored' to be 'false'", function(done) { | |
var errored = null; | |
function err() { | |
errored = true; | |
} | |
function success() { | |
errored = false; | |
} | |
Thing.load().then(success).catch(err) | |
.then(function () { | |
expect(errored).toBe(false); | |
done(); | |
}); | |
jasmine.Ajax.requests.mostRecent().respondWith({ | |
status: 200, | |
responseText: JSON.stringify({ | |
}) | |
}); | |
}); | |
}); |
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 Thing = { | |
load: function() { | |
var resolve, reject; | |
function finished() { | |
resolve({}) | |
} | |
function errored() { | |
reject({}); | |
} | |
function resolver(res, rej) { | |
resolve = res; | |
reject = rej; | |
$.getJSON("/thing", {success: finished, error: errored}); | |
} | |
return new Promise(resolver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment