我目前正在爲我的謙虛Angular應用程序使用量角器編寫一些e2e測試。如何期待使用量角器的e2e測試中的元素動態計數
我的應用程序工作正常,單元測試通過了所有,使用端對端太...直到這一個:
appE2ESpec.js
describe('adding an item', function() {
var items,
addItemButton,
startCount;
beforeEach(function() {
items = element.all(by.css('li.item'));
addItemButton = element(by.id('addItemButton'));
startCount = items.count();
});
it('should display a new item in list', function() {
addItemButton.click();
expect(items.count()).toEqual(startCount+1);
});
});
這是我會寫我的測試,但,
的問題是:是items.count()返回一個承諾,我知道,但我不能設法迫使量角器解決它。所以,我得到這個:
Failures:
1) myApp adding an item should display a new item in list
Message:
Expected 6 to equal '[object Object]1'.
我已經試過:
items.count().then(function(count) {
startCount = count;
//console.log(startCount) --> "6" Perfect!
});
,但得到的最終結果相同......我不能把expect
到then
,我也想過這個。
- 我搜索了Protractor GitHub存儲庫問題,StackOverflow和Google AngularJs組。
附錄:
console.log(startCount)
輸出這樣的:
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
我可以寫.toEqual(6)
但我不想每次我需要改變我的應用程序啓動狀態重寫我的測試。
有什麼想法?提前致謝!!
你是我的英雄!謝謝;)希望能幫助其他人以量角器開始:) – glepretre
我遇到了同樣的問題。他們應該在量角器中創建一個方法來解決這些承諾。他們不應該強迫程序員使用expect()來解決承諾。總會有一種情況,你將需要的價值,而不需要使用expect() – supertonsky
@glepretre我有同樣的問題,但..上述解決方案不起作用。我得到「預期3等於未定義」。錯誤。 –