javascript - Chai-As-Promised: Handle errors when promise throws error -


i have following code need test:

function a(param){   // process param   return b(param)      .catch(function(err){       //process err       throw new customerror(err); // throw custom error      })      .then(function(response){        // handle response , return        return {status: 'success'}      }) } 

to test it, use following snippet:

return expect(a(param))              .to.eventually.have.property('status', 'success'); 

this works fine when code doesn't break in function or b, when does, test case fails, , grunt-mocha fails exit, presume due fact still waiting resolve.

if add return statement instead of throw in catch block, grunt-mocha exits fine. there better way test such cases?

catch meant catch , correct errors, not re-throw them. returning error or rejected promise correct way handle this.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -