toBe(true), toBeTrue() and toBeTruthy() , toBeFalse() and toBeFalsy() Jamine matcher

 toBe(true), toBeTrue() and toBeTruthy() , toBeFalse() and toBeFalsy() Jamine matcher


toBe(true)

Matcher function performs the test: actual === expected

Syntax: expect(flag).toBe(true | false)

This test passes only if flag has the value true,

in the case of expect(flag).toBe(true).


toBeTrue()

Matcher function performs the test: (actual === true || is(actual, 'Boolean') && actual.valueOf())

Syntax: expect(flag).toBeTrue()

This function behaves the same way as toBe(true) but handles an additional case.

toBe(true) only handles a primitive boolean type.

ToBeTrue() handles both a primitive boolean type and a Boolean object.

 

ToBeTruthy()

This Boolean matcher is used in Jasmine to check whether the result is equal to true or false.

 

toBeFalsy()

toBeFalsy() also works the same way as toBeTruthy() method. It matches the output to be false whereas toBeTruthy matches the output to be true.

 

 

  expect(true).toBeTruthy(); // true

   expect('1').toBeTruthy(); // true

   expect(0).toBeTruthy(); // false

   expect(undefined).toBeTruthy(); // false

   expect(NaN).toBeTruthy(); // false

   expect(false).toBeTruthy(); // false

   expect('').toBeTruthy(); // false

 

you can learn more on it from below video




Share this

Related Posts

Previous
Next Post »