按照承诺归还承诺

时间:2017-10-09 17:06:29

标签: protractor angular-promise chai chai-as-promised

我是承诺的新手,我有以下功能

var chai = require('chai');
var expect = chai.expect;

var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

it('should do something with promises', function() {
    var blah = 'foo';

    var result = systemUnderTest();

    return expect(result).to.eventually.equal(blah);
});

为什么return之前有expect个关键字,它有什么意义?如果我们不return

会发生什么

1 个答案:

答案 0 :(得分:0)

您必须返回承诺以执行所有承诺链

<div class="teammember">
  <div class="teammember-photo">
    <img class="teammember-img" src="http://via.placeholder.com/300x300" alt="Image">
    <div class="teammember-details">
      <div class="teammember-details-top">
        <strong>Name</strong>
        <p>Function</p>
      </div>
      <div class="teammember-linkedin">
        <a href="#" target="_blank"><span class="linkedin"></span></a>
      </div>
    </div>
  </div>
</div>

如果您没有退回承诺,则可以在预期评估后执行块it('should do something with promises', function() { const expected = "test"; const promise = new Promise((resolve, reject) => { ...//Something to do }); promise.then(() => { return expected; }); return expect(promise).to.eventually.equal(expected); }); ;