AssertionError: expected [ true ] to be true

巧了我就是萌 提交于 2019-12-22 14:00:32

问题


I have faced with the strange assertions problem so even successful assertions are marked as failed, like this:

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

and in the console I have:

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

As you see in this case test marked as successful despite of failed assertion, but in case when after 'failed' assertion there is another one the whole thing will be failed.

I'm using the last versions of protractor and chai.


回答1:


It seems like this.getWidget('contacts').isNamesDisplayed() is returning an array value [true] instead of true. you need to change your expect statement as below.

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




回答2:


The accepted answer is great. The accepted answer reiterates the complaint from Protractor, which is frustrating but very clear:

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

Apparently that is the behavior of the OP's function isNamesDisplayed. But there may be other reasons:

In my case, I accidentally used $$, instead of $, and I was expect($$('div.to-test').isDisplayed()).toBe(true). $$ is a "Shorthand function for finding arrays of elements by css" .

So be aware that one character, $, could be the cause of (and solution to) all life's problems: expect($('div.to-test').isDisplayed()).toBe(true),

(or as the accepted answer says, you could just... "change your expectations" :) )

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

Maybe makes more sense for something you actually expect to repeat,for example the <li> list items in a <ul>

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



来源:https://stackoverflow.com/questions/39575594/assertionerror-expected-true-to-be-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!