Jest: Truthiness

expect('foo').toBeTruthy()Matches anything that an if statement treats as true (not false, 0, ”, null, undefined, NaN)
expect('').toBeFalsy()Matches anything that an if statement treats as false (false, 0, ”, null, undefined, NaN)
expect(null).toBeNull()Matches only null
expect(undefined).toBeUndefined()Matches only undefined
expect(7).toBeDefined()The opposite of toBeUndefined
expect(true).toEqual(expect.any(Boolean))Matches true or false

Leave a Reply

Your email address will not be published. Required fields are marked *