我是承诺的新手,我有以下功能
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
答案 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);
});
;