I want to write a Jasmine spec to test the success and error conditions of the following snippet. It should make the request, test of for failure and return a promise to the caller for further chaining.
var Promise = require('bluebird');
var request = Promise.promisifyAll(require("request"));
var requestOptions = {
method: 'POST',
url: 'http://some.url.com'
}
function makeRequestReturnPromise() {
return request(requestOptions)
.then(function(response){
if(response.statusCode != 202){
throw new Error(failureMessage(result));
}
});
}
I've tried different approaches to write a spec for this. Google turned up some options and I tried passing a stubbed request object in, tried sinon, sinon-as-promised, mockery and jasmine's spy objects but none of them give me the expected results for me test.
Aucun commentaire:
Enregistrer un commentaire