Skip to content

Instantly share code, notes, and snippets.

@thatmarvin
Created April 8, 2013 22:01
Show Gist options
  • Save thatmarvin/5340936 to your computer and use it in GitHub Desktop.
Save thatmarvin/5340936 to your computer and use it in GitHub Desktop.
var Q = require('q');
require('should');
require('mocha-as-promised')();
// This pretends to be the API client
function get(url) {
var deferred = Q.defer();
if (url === '/1') {
deferred.resolve([
{ id: 1, title: 'Hello' },
{ statusCode: 200 }
]);
} else {
var error = new Error('404 Not found');
error.code = 404;
deferred.reject(error);
}
return deferred.promise;
}
describe('When a resource does exist', function () {
it('should return HTTP 200', function () {
return get('/1').spread(function (body, res) {
res.should.have.status(200);
});
});
});
describe('When a resource does not exist', function () {
it('should return HTTP 404', function () {
return get('/2').spread(
function (body, res) {
res.should.have.status(404);
},
function (err) {
err.code.should.equal(404);
}
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment