项目作者: slowli

项目描述 :
Chai assertions for byte arrays equality
高级语言: JavaScript
项目地址: git://github.com/slowli/chai-bytes.git
创建时间: 2017-06-15T12:03:31Z
项目社区:https://github.com/slowli/chai-bytes

开源协议:Apache License 2.0

下载


Chai Assertions for Byte Arrays Equality

Build status
Code coverage
Code style
License

chai-bytes extends Chai with a equalBytes function,
which can be used to test equality of byte arrays (i.e., Uint8Array instances).

Basic Usage

  1. const { expect, assert } = require('chai')
  2. .use(require('chai-bytes'));
  3. const buffer = new Uint8Array([ 1, 2, 3, 4, 5 ]);
  4. expect(buffer).to.equalBytes('0102030405');
  5. // `assert` style works, too
  6. assert.equalBytes(buffer, [1, 2, 3, 4, 5], 'error message');

An expected value passed to equalBytes can be:

  • Hexadecimal string, e.g., 'c0ffee'
  • Array, e.g., [1, 2, 3]
  • Array-like object (i.e., an object having the length property
    and items accessible by integer properties).
    This includes Uint8Array instances, among other things

If the passed value does not fall into any of these categories,
a TypeError is thrown.

Developer Notes

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).

License

chai-bytes is available under Apache-2.0 license.