@typed/assertions
Get It
npm install --save-dev @typed/assertions# or yarn add --dev @typed/assertions
Basic usage
// with mochadescribe'Foo',
API
createAssertionsEnvironment(): AssertionEnvironment
Creates an Assertions Environment where assertions can be counted
Example:
console.logstats.count // => 0 oktrue console.logstats.count // => 1
equal<A>(expected: A, actual: A): A
Checks if 2 values are equal in terms of value equality
Example:
equal, // throws AssertionError
notEqual<A>(expected: A, actual: A): A
Checks if two values are not equal in terms of value equality
Example:
notEqual, // => { a: 2 } notEqual, // throws AssertionError
notOk(actual: boolean): boolean
Checks if a value is false
Example:
notOkfalse // => falsenotOktrue // throws AssertionError
ok(actual: boolean): boolean
Checks if a value is true
Example:
okfalse // throws AssertionErroroktrue // => true
rejects<Err extends Error>(promise: Promise<any>): Promise<Err>
Asserts that a Promise has rejected, returning a resolved Promise containing the error.
If the promise does not reject returns a rejected Promise.
Example:
rejectsPromise.rejectnew Error'foo))) // => resolved Promise containing Error('foo')rejectsPromise.resolve // => rejected Promise
same<A>(expected: A, actual: A): A
Checks if 2 values are the same in terms of ===
Example:
same, // throws AssertionErrorsame1, 1 // => 1
throws<Err extends Error>(fn: () => any): Err
Asserts that the given function throws
Example:
throws // => Error('foo')throws // throws Error