Angularjs 可能未处理的拒绝,使用$q.reject

Angularjs 可能未处理的拒绝,使用$q.reject,angularjs,jasmine,es6-promise,Angularjs,Jasmine,Es6 Promise,我正在用Angular和jasmine,得到了错误: createAccount() { // Return some ES6 Promise/async call with return value from test. return this.request({method: 'POST', body: {}}) .catch(error => { if (error.flaky) { // Handle a specific

我正在用Angular和jasmine,得到了错误:

createAccount() {
  // Return some ES6 Promise/async call with return value from test.
  return this.request({method: 'POST', body: {}})
      .catch(error => {
        if (error.flaky) {
            // Handle a specific error with another call
            return this.createDifferentAccount();
        }

        console.log('Passed the specific case');
        // Generically fail for other errors.
        this.$q_.reject(error);
      });
}
可能未处理的拒绝:{“body2”:{}}抛出

引发错误的我的代码:

createAccount() {
  // Return some ES6 Promise/async call with return value from test.
  return this.request({method: 'POST', body: {}})
      .catch(error => {
        if (error.flaky) {
            // Handle a specific error with another call
            return this.createDifferentAccount();
        }

        console.log('Passed the specific case');
        // Generically fail for other errors.
        this.$q_.reject(error);
      });
}
我的jasmine测试用例(失败):


如何处理此错误/我做错了什么?

您只是拒绝错误,而不是返回拒绝

解决办法很简单,改变一下

this.$q.拒绝(错误)

返回此项。$q\uu.拒绝(错误)

请记住始终从.then()或.catch()块中返回值