-
Notifications
You must be signed in to change notification settings - Fork 0
Assert
Anton edited this page Sep 2, 2019
·
2 revisions
Zoroaster comes with an assertion library @zoroaster/assert that exports the following methods to be used for assertions in tests:
-
equal which is
require('assert').equalfor equality assertions on primitives such as strings. -
ok which is
require('assert').okfor truthy assertions. -
deepEqual which is an alias for
@zoroaster/deep-equalfor assertions of complex objects, with red/green difference highlighting. It runsassert.strictEqualfirst and then uses an algorithm to show the differences in color. -
throws which is an alias for
assert-throwsfor assertions on the presence of errors in synchronous and asynchronous function calls. -
assert which is just
require('assert').equal.
import { equal, ok, deepEqual, throws, assert } from 'zoroaster'The assert-throws library is the easiest way to test whether an asynchronous function throws expected errors.
import { throws } from '@zoroaster/assert'
{
async 'throws an error when choosing an unknown side'() {
const zoroaster = new Zoroaster()
await throws({
async fn() {
await zoroaster.side(Zoroaster.MAGI), // follow yet unknown way
},
message: 'Unknown side',
})
},
}See assert-throws API documentation to learn more about assertions.