Assertions

API ReferenceAssertions

Access it with:

const { assert } = Neft;

Source


assert()

Parameters
  • expression — Boolean
  • message — Stringoptional

Throws AssertionError if the given expression is falsy.

Source

Class assert.AssertionError()

Access it with:

const { AssertionError } = Neft.assert;

Source


assert.scope()

Static method of
assert
Parameters
  • message — String
Returns
assert

Returns new assert namespace where all failues are prefixed by the given message.

Source


assert.ok()

Static method of
assert
Parameters
  • expression — Boolean
  • message — Stringoptional

Link to the main assert function.

Throws an error if the given expression is falsy.

Source


assert.notOk()

Static method of
assert
Parameters
  • expression — Boolean
  • message — Stringoptional

Throws an error if the given expression is truthy.

Source


assert.is()

Static method of
assert
Parameters
  • actual — Any
  • expected — Any
  • message — Stringoptional

Throws an error if the given actual is not the same as expected.

Strict comparison operator is used in this operation (===). Types needs to be the same. Read more about comparison operators in JavaScript.

Source


assert.isNot()

Static method of
assert
Parameters
  • actual — Any
  • expected — Any
  • message — Stringoptional

Throws an error if the given actual is the same as expected.

Strict comparison operator is used in this operation (===).

Source


assert.isDefined()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is null or undefined.

Source


assert.isNotDefined()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is not null or undefined.

Source


assert.isPrimitive()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is not a primitive value.

Primitive value must be null, string, number, boolean or undefined.

Source


assert.isNotPrimitive()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value if a primitive value.

Primitive value must be null, string, number, boolean or undefined.

Source


assert.isString()

Static method of
assert
Parameters
  • value — String
  • message — Stringoptional

Throws an error if the given value is not a string.

Source


assert.isNotString()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a string.

Source


assert.isFloat()

Static method of
assert
Parameters
  • value — Float
  • message — Stringoptional

Throws an error if the given value is not a float number.

Float number needs to be finite and may be an integer.

Source


assert.isNotFloat()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a float number.

Float number needs to be finite and may be an integer.

Source


assert.isInteger()

Static method of
assert
Parameters
  • value — Integer
  • message — Stringoptional

Throws an error if the given value is not an integer.

Source


assert.isNotInteger()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is an integer.

Source


assert.isBoolean()

Static method of
assert
Parameters
  • value — Boolean
  • message — Stringoptional

Throws an error if the given value is not a boolean.

Source


assert.isNotBoolean()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a boolean.

Source


assert.isFunction()

Static method of
assert
Parameters
  • value — Function
  • message — Stringoptional

Throws an error if the given value is not a function.

Source


assert.isNotFunction()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a function.

Source


assert.isObject()

Static method of
assert
Parameters
  • value — Object
  • message — Stringoptional

Throws an error if the given value is not an object.

Arrays are objects.

null is not an object.

Source


assert.isNotObject()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is an object.

Arrays are objects.

null is not an object.

Source


assert.isPlainObject()

Static method of
assert
Parameters
  • value — PlainObject
  • message — Stringoptional

Throws an error if the given value is not a plain object.

Plain object in an object with no prototype or direct standard Object prototype.

Arrays and instances of classes are not plain objects.

Source


assert.isNotPlainObject()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is a plain object.

Plain object in an object with no prototype or direct standard Object prototype.

Arrays and instances of classes are not plain objects.

Source


assert.isArray()

Static method of
assert
Parameters
  • value — Array
  • message — Stringoptional

Throws an error if the given value is not an array.

Typed arrays are not arrays.

Source


assert.isNotArray()

Static method of
assert
Parameters
  • value — Any
  • message — Stringoptional

Throws an error if the given value is an array.

Source


assert.isEqual()

Static method of
assert
Parameters
  • value1 — Any
  • value2 — Any
  • message — Stringoptional
  • options — Objectoptional

Throws an error if the given values are not equal.

Objects and arrays are tested recursively.

Maximum deepness may be specified by options.maxDeep. Default value is Infinity.

Source


assert.isNotEqual()

Static method of
assert
Parameters
  • value1 — Any
  • value2 — Any
  • message — Stringoptional
  • options — Objectoptional

Throws an error if the given values are equal.

Source


assert.instanceOf()

Static method of
assert
Parameters
  • object — Object
  • constructor — Function
  • message — Stringoptional

Throws an error if the given object is not an instance of the given constructor.

Source


assert.notInstanceOf()

Static method of
assert
Parameters
  • object — Any
  • constructor — Function
  • message — Stringoptional

Throws an error if the given object is an instance of the given constructor.

Source


assert.lengthOf()

Static method of
assert
Parameters
  • value — Any
  • length — Integer
  • message — Stringoptional

Throws an error if the given value object length is not equal the given length.

Source


assert.notLengthOf()

Static method of
assert
Parameters
  • value — Any
  • length — Integer
  • message — Stringoptional

Throws an error if the given value object length is equal the given length.

Source


assert.operator()

Static method of
assert
Parameters
  • value1 — Any
  • operator — String
  • value2 — Any
  • message — Stringoptional

Throws an error if the given operator comparison is falsy on the given values.

operator is a string as follow: >, >=, <, or <=. TypeError is thrown if unexpected operator has been given.

Example:

assert.operator(2, '>', 1); // true
assert.operator(2, '<=', 1); // AssertionError

Source


assert.match()

Static method of
assert
Parameters
  • value — Any
  • regexp — RegExp
  • message — Stringoptional

Throws an error if the given regexp does not test on the given value.

Example:

assert.match('12', /[0-9]+/); // true

Source


assert.notMatch()

Static method of
assert
Parameters
  • value — Any
  • regexp — RegExp
  • message — Stringoptional

Throws an error if the given regexp tests on the given value.

Source

results matching ""

    No results matching ""