These are the most basic expectations about the type of a subject.
Success:
expect('hello, world!', 'to be a string');
Failure:
expect(42, 'to be a string');
// AssertionError: Expected 42 to be a string
Negation:
expect(42, 'not to be a string');
Aliases:
to be a boolean
,to be a bool
,to be boolean
Success:
expect(true, 'to be a boolean');
expect(false, 'to be a boolean');
Failure:
expect(0, 'to be a boolean');
// AssertionError: Expected 0 to be a boolean
Negation:
expect(0, 'not to be a boolean');
Aliases:
to be a number
,to be finite
The definition of "number" is that of Zod v4's; only finite numbers are considered valid.
Success:
expect(3.14, 'to be a number');
expect(-42, 'to be a number');
expect(0, 'to be a number');
Failure:
expect(NaN, 'to be a number');
// AssertionError: Expected NaN to be a number
expect(Infinity, 'to be a number');
Negation:
expect(NaN, 'not to be a number');
expect(Infinity, 'not to be a number');
Success:
expect(9007199254741991n, 'to be a bigint');
Failure:
expect(42, 'to be a bigint');
// AssertionError: Expected 42 to be a bigint
Negation:
expect(42, 'not to be a bigint');
Success:
expect(Symbol('foo'), 'to be a symbol');
Failure:
expect('foo', 'to be a symbol');
// AssertionError: Expected 'foo' to be a symbol
Negation:
expect('foo', 'not to be a symbol');
Success:
expect(null, 'to be null');
Failure:
expect(undefined, 'to be null');
// AssertionError: Expected undefined to be null
Negation:
expect(undefined, 'not to be null');
Success:
expect(undefined, 'to be undefined');
Failure:
expect(null, 'to be undefined');
// AssertionError: Expected null to be undefined
Negation:
expect(null, 'not to be undefined');
Success:
expect('hello', 'to be a primitive');
expect(42, 'to be a primitive');
expect(true, 'to be a primitive');
expect(null, 'to be a primitive');
expect(undefined, 'to be a primitive');
expect(Symbol('test'), 'to be a primitive');
expect(123n, 'to be a primitive');
Failure:
expect({}, 'to be a primitive');
// AssertionError: Expected {} to be a primitive
expect([], 'to be a primitive');
Negation:
expect({}, 'not to be a primitive');
expect([], 'not to be a primitive');