DEFAULT_TEMPLATE

Type-checking utilities

DEFAULT_TEMPLATE
Version: 1.0.0
Author: Michael Ko <koyote130708@gmail.com>

true

Checks if the value is true and throws an error if not.

true(value: any, name: string?, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any) The value to check.
name (string?) The name of the value
errorMsg (string?) A custom message to describe the error.
Returns
any: the value passed.
Related
Types.isTrue
Throws
Example

Valid inputs

expect.true(true);

Invalid inputs

expect.true(false); 
// => TypeError: Expected the value to be true, but found: false

expect.true(false, "canFly");
// => TypeError: Expected canFly to be true, but found: false

expect.true(false, "canFly", "${name} should be true, but found: ${actual}");
// => TypeError: canFly should be true, but found: false

false

Checks the value is false.

false(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

undefined

Checks the value is not undefined.

undefined(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

null

Checks the value is not undefined.

null(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

boolean

Checks the value is a boolean.

boolean(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a primitive boolean value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

number

Checks the value is a number.

number(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a primitive number.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

string

Checks the value is a string.

string(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a primitive string.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

object

Ensues the value is an object.

object(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an instance of Object.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

function

Checks the value is a function.

function(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an instance of Function.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

array

Checks the value is an array.

array(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an instance of Array.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

arrayOf

Checks the value is an array.

arrayOf(value: any, type: (string | Function), name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
type ((string | Function)) a custom message to describe the error.
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an instance of Array.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

arrayLike

Checks the value is an array-like object.

arrayLike(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an array-like object.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

symbol

Checks the value is a Symbol.

symbol(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

bigInt

Checks the value is a BigInt.

bigInt(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

date

Checks the value is a BigInt.

date(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

map

Checks the value is a BigInt.

map(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

set

Checks the value is a BigInt.

set(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

weakMap

Checks the value is a BigInt.

weakMap(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

weakSet

Checks the value is a BigInt.

weakSet(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

regExp

Checks the value is a BigInt.

regExp(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

promise

Checks the value is a BigInt.

promise(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

promiseLike

Checks the value is a BigInt.

promiseLike(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

iterable

Checks the value is an iterable.

iterable(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an array-like object.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

error

Checks the value is an iterable.

error(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not an array-like object.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

primitive

Checks the value is a primitive type.

primitive(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a primitive type.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

plainObject

Checks the value is a plain object.

plainObject(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a plain object.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

truthy

Checks the value is a truthy value. All values are truthy unless they are defined as falsy (i.e., except for false, 0, 0n, "", null, undefined, and NaN).

truthy(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • Error: if the value is not a truthy value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

falsy

Checks the value is a falsy value. There are 7 falsy values in JavaScript: false, 0, 0n, "", null, undefined, and NaN.

falsy(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • Error: if the value is not a falsy value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

nullish

Checks the value is not null or undefined.

nullish(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is null or undefined.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

empty

Checks the value is not null or undefined.

empty(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is null or undefined.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

blank

Checks the value is not null or undefined.

blank(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is null or undefined.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

numeric

Checks the value is a numeric value.

numeric(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a numeric value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

integer

Checks the value is a numeric value.

integer(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a numeric value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

float

Checks the value is a numeric value.

float(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a numeric value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

finite

Checks the value is a numeric value.

finite(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a numeric value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

infinite

Checks the value is an infinite value.

infinite(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • TypeError: if the value is not a numeric value.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

NaN

Checks the value is NaN.

NaN(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

nativeFunction

Checks the value is a native function.

nativeFunction(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • Error: if the value is a non-native function or is not a function.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

typeOf

Checks the value has the specified type.

typeOf(value: any, type: (string | Function | Array | null | undefined), errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
type ((string | Function | Array | null | undefined))
errorMsg (string?)
Returns
any: the value passed.
Throws
  • TypeError: if the value does not have the specified type.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

inRange

Checks the value has the specified type.

inRange(value: any, name: any, errorMsg: string?, type: (string | Function | Array | null | undefined)): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?)
type ((string | Function | Array | null | undefined))
Returns
any: the value passed.
Throws
  • TypeError: if the value does not have the specified type.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

equalTo

Checks the value has the specified type.

equalTo(value: any, name: any, errorMsg: string?, type: (string | Function | Array | null | undefined)): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?)
type ((string | Function | Array | null | undefined))
Returns
any: the value passed.
Throws
  • TypeError: if the value does not have the specified type.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

notUndefined

Checks the value is not undefined.

notUndefined(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

notNull

Checks the value is not null.

notNull(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

notNaN

Checks the value is NaN.

notNaN(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);

notNativeFunction

Checks the value is a non-native function.

notNativeFunction(value: any, name: any, errorMsg: string?): any
Since: 1.0.0
Parameters
value (any)
name (any)
errorMsg (string?) a custom message to describe the error.
Returns
any: the value passed.
Throws
  • Error: if the value is a native function or is not a function.
Example

Valid inputs

// no error
expect.boolean(true);

Invalid inputs

// throws an error
expect.boolean(1);