Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js expect check中使用的量角器等待异步函数_Node.js_Asynchronous_Protractor - Fatal编程技术网

Node.js expect check中使用的量角器等待异步函数

Node.js expect check中使用的量角器等待异步函数,node.js,asynchronous,protractor,Node.js,Asynchronous,Protractor,嘿嘿, 我正在使用量角器来运行e2e测试,并希望有类似的东西: expect(element(by.model('someModel')).getText()).toContain(asyncMethodResult()); 我希望避免这样做: asyncMethodResult().then(function(result){ expect(element(by.model('someModel').getText()).toContain(result); }); 也可能在bef

嘿嘿,

我正在使用量角器来运行e2e测试,并希望有类似的东西:

expect(element(by.model('someModel')).getText()).toContain(asyncMethodResult());
我希望避免这样做:

asyncMethodResult().then(function(result){
    expect(element(by.model('someModel').getText()).toContain(result);
});
也可能在beforeach中运行异步请求,这也会“阻止”进一步执行,直到完成

这可行吗?这样做的唯一方法是什么

[更新]为了回答问题:

it('test spec', function () {
   var expectFn = function (x, t) {
      var deferred = Q.defer();
      setTimeout(function () {
        console.log('Timeout complete:', x, t);
        deferred.resolve(x);
      }, t);
      return deferred.promise;
   };
   expect(expectFn(3, 1000)).toEqual(expectFn(4, 2000));
}
正确通过或失败(取决于x值),如果:

在这种情况下,量角器等待“Y”毫秒,然后比较值,否则比较始终通过

如果implicitWait小于超时,则它总是立即通过第一个案例(
expect(…)。toContain(asyncMethodResult())
应该已经起作用。请参阅示例测试

也可以在每个块之前的
中运行异步请求。以下是一个示例:

beforeEach(function(done) {
    doSyncStuff();
    doAsyncStuff.then(done);
});

我正在用“testFn(returnVal,timeout)”测试它(它只调用setTimeout并用returnVal解析承诺)。在您回答后,我删除了browser.manage().timeouts().implicitlyWait(25000)值,并且测试总是通过:我还尝试使用:var flow=dragotor.promise.controlFlow();flow.execute(函数(){///ASYNC operations}。然后(function(){///EXPECTS});这也会超时/始终传递
beforeEach(function(done) {
    doSyncStuff();
    doAsyncStuff.then(done);
});