这里是失败的测试:失败期望:“预期[]为空阵列。”
describe("Checking errors", function() {
var scope = {};
beforeEach(function() {
browser.get("/#endpoint");
browser.waitForAngular();
scope.page = new MyPage();
});
it("should not show any errors", function() {
expect(scope.page.errors).toBeEmptyArray();
});
});
其中MyPage
是Page对象:
var MyPage = function() {
this.errors = element.all(by.css("div.error-block b.error"))
.filter(function (elm) {
return elm.isDisplayed().then(function (value) {
return value;
});
})
.map(function (elm) {
return elm.getText();
});
};
module.exports = MyPage;
其中errors
应该是在网页上找到明显的错误文本的数组。
这是我们所得到的错误:
Failures:
1) Checking errors should not show any errors
Message:
Expected [ ] to be empty array.
Stacktrace:
Error: Failed expectation
仅供参考,toBeEmptyArray()
匹配从jasmine-matchers
第三方来。
我试着打印出值的scope.page.errors
这样:
scope.page.errors.then(function (errors) {
console.log(errors);
});
而且它打印出来[]
。 Array.isArray(errors)
返回true
。
从我看到的,scope.page.errors
是一个空数组,但期望失败。我错过了什么?
什么,如果你登录Array.isArray(你会做错误)? – Ryan 2015-03-18 23:12:59
@Ryan并不期待这一点,但它打印出'真实'......很奇怪。谢谢。 – alecxe 2015-03-18 23:15:46
'expect(scope.page.errors.length).toBe(0);'工作吗?您可能会遇到webdriver创建的范围(如页面中的iframe)中有自己的“Array”定义的问题。请参阅http://stackoverflow.com/a/2265999/960524(这可能是'toBeEmptyArray()'方法中的一个错误 - 它可能会失败检查的“数组”部分。) – 2015-03-18 23:36:26