Protractor 如何像承诺的那样与柴一起使用Q.all?

Protractor 如何像承诺的那样与柴一起使用Q.all?,protractor,q,cucumberjs,chai-as-promised,Protractor,Q,Cucumberjs,Chai As Promised,chai as promised docs在同一测试中处理多个承诺的示例如下: 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,

chai as promised docs在同一测试中处理多个承诺的示例如下:

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安装Q
var Q=require('Q')

应该来自哪里

当我尝试此
时,should
未定义的
并且我得到
类型错误:无法调用未定义的方法'notify'

是否有一些应该首先发生的
Q
的猴子补丁?还是我使用了错误的版本


我在用黄瓜和量角器。据我所知,他们还不支持返回承诺,因此用户必须处理对
done
的调用。如果我理解正确,Q-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")
    ]).then(done);
});
您还可以按照承诺使用require
摩卡,如下所示:

require("mocha-as-promised")();

it("should all be well", function (done) {
    return Q.all([
            promiseA.then(function(someData){
                //here standart chai validation;
            }),
            promiseB.then(function(someData){
                //here standart chai validation;
            });
    ]).then(done);
});
好的,您要在代码中添加下一行吗

var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");

chai.use(chaiAsPromised);

回答我自己的问题:

.should
来自“should”断言样式-。您需要运行:

chai.should();
var Q=require('Q')之后但在
Q.all([])之前。应通知…

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);
});
根据文件:

这将把单个承诺断言的任何失败传递给测试框架


不幸的是,这不能正确地将测试状态传递给框架。我已经计算出
应该从哪里来;我想我会回答我自己的问题。。。