Skip to content

Instantly share code, notes, and snippets.

@Nepoxx
Last active December 10, 2015 17:05
Show Gist options
  • Save Nepoxx/2d37d3d405173f0f7736 to your computer and use it in GitHub Desktop.
Save Nepoxx/2d37d3d405173f0f7736 to your computer and use it in GitHub Desktop.
testing module that uses bluebirdd
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({
})
});
});
});
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