Created
April 8, 2013 22:01
-
-
Save thatmarvin/5340936 to your computer and use it in GitHub Desktop.
This file contains 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 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