toBe(true) vs toBeTruthy() vs toBeTrue()

后端 未结 4 1071
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 19:12

What is the difference between expect(something).toBe(true), expect(something).toBeTruthy() and expect(something).toBeTrue()?

Note

4条回答
  •  时光取名叫无心
    2021-01-29 19:22

    There are a lot many good answers out there, i just wanted to add a scenario where the usage of these expectations might be helpful. Using element.all(xxx), if i need to check if all elements are displayed at a single run, i can perform -

    expect(element.all(xxx).isDisplayed()).toBeTruthy(); //Expectation passes
    expect(element.all(xxx).isDisplayed()).toBe(true); //Expectation fails
    expect(element.all(xxx).isDisplayed()).toBeTrue(); //Expectation fails
    

    Reason being .all() returns an array of values and so all kinds of expectations(getText, isPresent, etc...) can be performed with toBeTruthy() when .all() comes into picture. Hope this helps.

提交回复
热议问题