$ npm install chai-bites
Fork of chai-bytes published as ESM with relaxed input types.
chai-bytes extends Chai with a equalBytes function,
which can be used to test equality of byte arrays (i.e., Uint8Array instances).
const { expect, assert } = require('chai')
.use(require('chai-bytes'));
const buffer = new Uint8Array([ 1, 2, 3, 4, 5 ]);
expect(buffer).to.equalBytes('0102030405');
// `assert` style works, too
assert.equalBytes(buffer, [1, 2, 3, 4, 5], 'error message');
An expected value passed to equalBytes can be:
'c0ffee'[1, 2, 3]length property
and items accessible by integer properties).
This includes Uint8Array instances, among other thingsIf the passed value does not fall into any of these categories,
a TypeError is thrown.
chai-bytes uses combined code coverage from the tested browser environments
(Firefox and PhantomJS). This is because PhantomJS is a typical old environment
that may have problems with Uint8Arrays (e.g., it misses a substantial parts
of their methods).
chai-bytes is available under Apache-2.0 license.
© 2010 - cnpmjs.org x YWFE | Home | YWFE