2016-09-19 95 views
2

我已經面對陌生的斷言問題,所以即使是成功的斷言標記爲失敗,就像這樣:Asse田:預計[真]是真實的

this.expect(this.getWidget('contacts').isNamesDisplayed()).to.eventually.be.true.and.notify(next); 

並在控制檯中我有:

1 scenario (1 passed) 4 steps (4 passed) 0m03.618s [17:06:38] E/launcher - expected [ true ] to be true [17:06:38] E/launcher - AssertionError: expected [ true ] to be true

正如你在這種情況下所看到的那樣,儘管斷言失敗,但測試標記爲成功,但在'失敗'斷言之後還有另一個失敗。

我正在使用量角器和柴的最後版本。

回答

3

看起來好像this.getWidget('contacts').isNamesDisplayed()返回數組值[true]而不是true。你需要改變你的期望陳述如下。

this.expect(this.getWidget('contacts').isNamesDisplayed()).to.eql([true]).and.notify(next);

+0

我檢查過,你的代碼失敗: AssertionError:expected [true]等於[true] –

+0

已更新我的回答。使用'to.eql()'而不是'to.Equal()'。有關'to.eql()'[http://chaijs.com/api/bdd/#arguments-section]的更多信息 –

+0

謝謝,它的工作原理。 –

0

接受的答案很好。接受答案重申從量角器的投訴,這是令人沮喪,但很清楚的:

... returning an array value [true]...

顯然這是OP的功能isNamesDisplayed的行爲。但可能還有其他原因:

在我的情況下,我不小心使用了$$而不是$,而我是expect($$('div.to-test').isDisplayed()).toBe(true)$$是「Shorthand function for finding arrays of elements by css」。

所以,要知道,一個字符,$,可能的原因(和解決方案)的所有生活中的問題:expect($('div.to-test').isDisplayed()).toBe(true)

(或接受的答案說,你可能只是...「改變你的期待」 :))

expect($$('div.to-test').isDisplayed()).toBe([true]);

也許更有意義的東西,你其實希望重複,例如在<ul>

<li>列表項

expect($$('ul.to-test li').isDisplayed()).toBe([true, true, true]);