我是第一次写一些BDD单元测试,我想为我的一个测试套件消除一些重复的代码。以下异步单元测试代码工作正常,但我想以某种方式在beforeEach()块中设置Promise,因为我将编写更多it()测试,并且每个都需要运行{ {1}}致电。感谢
db.find(...)
答案 0 :(得分:1)
这样的事情可以起作用
describe('DB retrieve row', function() {
var promise;
beforeEach(function () {
promise = db.find('P9GV8CIL')
});
it("returns a least one result", function () {
function success(orderData) {
// keep the following line in this it() block
expect(orderData.length).to.be.ok;
}
function fail(error) {
new Error(error);
}
return promise.then(success).catch(fail);
});
});