使用或不使用通知方法调用 chai-as-promised 有什么区别?
What is the difference between calling chai-as-promised with or without a notify method?
我正在使用 chai
和 chai-as-promised
来测试一些异步 JS 代码。
我只是想检查一个 return 承诺的函数最终会 return 一个数组并编写了以下 2 个测试:
A:
it('should return an array', () => {
foo.bar().should.eventually.to.be.a('array')
})
B:
it('should return an array', (done) => {
foo.bar().should.eventually.to.be.a('array').notify(done)
})
两者都通过了 OK,但只有 B 选项实际运行了我的 bar() 函数中包含的完整代码(即显示来自代码的 console.log()
消息以下)。难道我做错了什么?为什么会这样?
bar() {
return myPromise()
.then((result) => {
console.log('Doing stuff')
return result.body.Data
})
.catch((e) => {
console.err(e)
})
}
我正在使用 chai
和 chai-as-promised
来测试一些异步 JS 代码。
我只是想检查一个 return 承诺的函数最终会 return 一个数组并编写了以下 2 个测试:
A:
it('should return an array', () => {
foo.bar().should.eventually.to.be.a('array')
})
B:
it('should return an array', (done) => {
foo.bar().should.eventually.to.be.a('array').notify(done)
})
两者都通过了 OK,但只有 B 选项实际运行了我的 bar() 函数中包含的完整代码(即显示来自代码的 console.log()
消息以下)。难道我做错了什么?为什么会这样?
bar() {
return myPromise()
.then((result) => {
console.log('Doing stuff')
return result.body.Data
})
.catch((e) => {
console.err(e)
})
}