gpt4 book ai didi

protractor - 如何将 Q.all 与 chai-as-promised 一起使用?

转载 作者:行者123 更新时间:2023-12-03 23:20:55 24 4
gpt4 key购买 nike

chai-as-promised 文档有以下在同一测试中处理多个 promise 的示例:

it("should all be well", function (done) {
Q.all([
promiseA.should.become("happy"),
promiseB.should.eventually.have.property("fun times"),
promiseC.should.be.rejectedWith(TypeError, "only joyful types are allowed")
]).should.notify(done);
});

我假设 Q这里来自npm install qvar Q = require('q'); .

.should 在哪里从哪里来?

当我尝试这个时 shouldundefined我得到 TypeError: Cannot call method 'notify' of undefined .

Q 有猴子补丁吗?那应该先发生?还是我使用了错误的版本?

我正在使用带有 Protractor 的 cucumber 。据我了解,他们还不支持返回 promise ,因此用户必须处理对 done 的调用。 .

最佳答案

回答我自己的问题:

.should 来自“should”断言样式 - http://chaijs.com/guide/styles/#should .你需要运行:

chai.should();

var Q = require('q'); 之后但在 Q.all([]).should.notify... 之前:

var Q = require('q');
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

// ***************
chai.should();
// ***************

chai.use(chaiAsPromised);

it("should all be well", function (done) {
Q.all([
promiseA.should.become("happy"),
promiseB.should.eventually.have.property("fun times"),
promiseC.should.be.rejectedWith(TypeError, "only joyful types are allowed")
]).should.notify(done);
});

根据文档:

This will pass any failures of the individual promise assertions up to the test framework

关于protractor - 如何将 Q.all 与 chai-as-promised 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28855210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com