@typed/assertions
v1.1.0
Published
Well-typed functional assertion library
Downloads
81
Readme
@typed/assertions
Get It
npm install --save-dev @typed/assertions
# or
yarn add --dev @typed/assertions
Basic usage
import { equal, ok } from '@typed/assertions'
class Foo {
constructor() {
this.bar = 'bar'
}
}
// with mocha
describe('Foo', () => {
it(`does bar`, () => {
const foo = new Foo()
ok(foo instanceof Foo)
equal('bar', foo.bar)
})
})
API
import { createAssertionsEnvironment } from '@typed/assertions'
const { stats, assertions } = createAssertionsEnvironment()
const { ok } = assertions
console.log(stats.count) // => 0
ok(true)
console.log(stats.count) // => 1
import { equal } from '@typed/assertions'
equal({ a: 1 }, { a: 2 }) // throws AssertionError
import { notEqual } from '@typed/assertions'
notEqual({ a: 1 }, { a: 2 }) // => { a: 2 }
notEqual({ a: 1 }, { a: 1 }) // throws AssertionError
import { notOk } from '@typed/assertions'
notOk(false) // => false
notOk(true) // throws AssertionError
import { ok } from '@typed/assertions'
ok(false) // throws AssertionError
ok(true) // => true
import { rejects } from '@typed/assertions'
rejects(Promise.reject(new Error('foo))) // => resolved Promise containing Error('foo')
rejects(Promise.resolve()) // => rejected Promise
import { same } from '@typed/assertions'
same({}, {}) // throws AssertionError
same(1, 1) // => 1
import { throws } from '@typed/assertions'
throws(() => { throw new Error('foo') }) // => Error('foo')
throws(() => {}) // throws Error