Skip to main content

Boolean

.toBeBoolean()

Use .toBeBoolean when checking if a value is a Boolean.

test('passes when value is a boolean', () => {
  expect(false).toBeBoolean();
  expect(true).toBeBoolean();
  expect(1 === 1).toBeBoolean();
  expect(1).not.toBeBoolean();
});

Open browser consoleTests

.toBeTrue()

Use .toBeTrue when checking a value is equal (===) to true.

const isJestCool = () => true;

test('is jest cool', () => {
  expect(isJestCool()).toBeTrue();
  expect(false).not.toBeTrue();
});

Open browser consoleTests

.toBeFalse()

Use .toBeFalse when checking a value is equal (===) to false.

const areWeThereYet = () => false;

test('returns false', () => {
  expect(areWeThereYet()).toBeFalse();
  expect(true).not.toBeFalse();
});

Open browser consoleTests