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
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.
Even though this is not a new question I thought it deserves an exact answer.
expect('apple').toBe(true);
evaluates to 'apple' === true. (actual === expected in the jasmine code) I would prefer
expect('apple').toBe('apple');
That way you know you are not getting an 'orange'. On the other hand.
expect('apple').toBeTruthy();
evaluate 'apple' as !!'apple' (!!actual in the jasmine code). So not not 'apple'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With