class Assertion
Represents a value ready to be asserted.
class Assertion<T>
Constructor
- constructor(value, name?)Creates a new assertion using given value to test.
Instance Members
- value readonlyThe value being asserted.
- name readonlyThe name of the assertion, used in error messages.
- not readonlyEvaluates to a new negated assertion, where all methods mean the opposite of those on the current instance.
- asArray()Returns a new assertion for the return value of
Array.from(...)
on the current value. - asBoolean()Returns a new assertion for the boolean representation of the current value.
- asString()Returns a new assertion for the string representation of the current value.
- asNumber()Returns a new assertion for the number representation of the current value.
- asJSONString(replacer?, space?)Returns a new assertion for the JSON representation of the current value.
- toBe(value?)Asserts that the value is strictly equal to given value (using the
===
operator). - toBeOneOf(…values)Asserts that the value is strictly equal to one of given values.
- toEqual(value)Asserts that the value is loosely equal to given value (using the
==
operator). - toEqualOneOf(…values)Asserts that the value is loosely equal to one of given values.
- toBeLessThan(value)Asserts that the value is less than given value.
- toBeGreaterThan(value)Asserts that the value is greater than given value.
- toBeLessThanOrEqualTo(value)Asserts that the value is less than or equal to given value.
- toBeGreaterThanOrEqualTo(value)Asserts that the value is greater than or equal to given value.
- toBeTruthy()Evaluates asBoolean().toBe(true).
- toBeFalsy()Evaluates asBoolean().toBe(false).
- toBeUndefined()Evaluates toBe(undefined).
- toBeDefined()Evaluates toBeUndefined().
- toBeNull()Evaluates toBe(null).
- toBeNaN()Asserts that the value is
NaN
. - toBeTypeOf(typeStr)Asserts that the value is of given type.
- toBeArray(match?)Asserts that the value is an array, optionally with given length or elements.
- toBeInstanceOf(C)Asserts that the value is an instance of given class (using the
instanceof
operator). - toMatchRegExp(re)Asserts that the value is a string that matches given regular expression.
- toHaveProperty(propertyName)Asserts that the value is an object that includes a property with given name (using the
in
operator). - toHaveProperties(object)Asserts that the value is an object that includes the same properties with the same values (strict equals) as the specified object.
- toHaveMethod(methodName)Asserts that the value is an object that includes a function property with given name.
- toThrowError(…args)Runs a function and asserts that it throws an error when called with given arguments.
- toThrowErrorAsync(…args)Runs a function and asserts that it throws an error or results in a promise that’s rejected.