2016-12-06 136 views
1

我是角/量角器領域的新手,所以這是一個非常基本的問題。根據這一spec,我們可以寫量角器測試網絡元素象下面這樣:量角器中的測試承諾

var foo = element(by.id('foo')); 
expect(foo.getText()).toEqual('Inner text'); 

然而,foo.getText()返回一個承諾類型,而不是一個字符串,怎麼能「應該出現」比較是返回承諾對象對另一個字符串?有沒有解釋這種用法的文檔?

回答

3

是的,expect(),如果與Protractor使用,理解承諾 - 做它的期望使得編寫量角器測試之前容易就解決的承諾。這實際上是在一個單獨的項目中完成的,其中Protractor取決於 - jasminewd2其中patches jasmine's expect() to resolve the promiseswraps jasmine's describe(), it() and other test control block functions要在控制流程內執行。

需要注意的是,它還支持both sides of the assertion承諾,你可以做,例如:

let elementText1 = $('.ng-scope p').getText(); 
let elementText2 = $('#transformedtext>h4').getText(); 

expect(elementText1).toEqual(elementText2); 

至於Protractor文檔推移,這部分描述here

+0

是的,它只是解決這個問題。好的答案,upvoted – Maccurt