为什么量角器有时 returns 一个承诺,有时 returns 个值?
Why does Protractor sometimes returns a promise and sometimes returns a value?
在official documentation中可以找到以下代码:
var history = element.all(by.repeater('result in memory'));
expect(history.count()).toEqual(2);
不过你也可以找到
element.all(by.repeater('app in userApps')).count().then(function(count) {
console.log(count);
});
那么为什么 Protractor 有时 returns 一个承诺,有时它 returns 一个值?
history.count()
做了 return 承诺,但 Protractor 改编 Jasmine expect
来理解承诺。
https://github.com/angular/protractor/blob/master/docs/control-flow.md
the protractor folks "patched" jasmine to be promise aware. that is,
the expect statement does duck-typing -- if it is a promise, it waits
for it to resolve and executes the underlying assertion. if it is any
other type, it executes the assertion as it would in any other jasmine
world.
它总是 returns 一个承诺,只是 expect
被修补以通过将它们添加到 control-flow 来处理它们,以便它们以正确的顺序执行和解析。
在official documentation中可以找到以下代码:
var history = element.all(by.repeater('result in memory'));
expect(history.count()).toEqual(2);
不过你也可以找到
element.all(by.repeater('app in userApps')).count().then(function(count) {
console.log(count);
});
那么为什么 Protractor 有时 returns 一个承诺,有时它 returns 一个值?
history.count()
做了 return 承诺,但 Protractor 改编 Jasmine expect
来理解承诺。
https://github.com/angular/protractor/blob/master/docs/control-flow.md
the protractor folks "patched" jasmine to be promise aware. that is, the expect statement does duck-typing -- if it is a promise, it waits for it to resolve and executes the underlying assertion. if it is any other type, it executes the assertion as it would in any other jasmine world.
它总是 returns 一个承诺,只是 expect
被修补以通过将它们添加到 control-flow 来处理它们,以便它们以正确的顺序执行和解析。