protractor- difference between toBe(truth) and toBeTruthy()

user2880391 picture user2880391 · Feb 24, 2015 · Viewed 14.4k times · Source

as the title says- is there a difference between (for example)

 expect(element).isDisplayed().toBeTruthy();

and

 expect(element).isDisplayed().toBe(truth);

and if so what is the difference?

thanks

Answer

hankduan picture hankduan · Feb 24, 2015

Many things are Truthy (i.e. anything that is not one of: false, 0, "", undefined, null, NaN). So

expect('apple').toBeTruthy();

passes. But:

expect('apple').toBe(true);

fails.

That being said, if you know you are testing a boolean, to me using toBeTruthy looks nicer.