# chai-bites

> Chai assertions for byte arrays equality

Latest version **0.3.1** (published 2026-05-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install chai-bites
pnpm add chai-bites
yarn add chai-bites
bun add chai-bites
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2026-05-23 |
| First published | 2021-12-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Ostrovski |
| Maintainers | achingbrain |
| Keywords | chai, chai-plugin, assertions, testing, buffers, uint8array |

## Links

- npm: https://www.npmjs.com/package/chai-bites
- Repository: https://github.com/achingbrain/chai-bites
- Homepage: https://github.com/achingbrain/chai-bites#readme
- Issues: https://github.com/achingbrain/chai-bites/issues
- npm.io page: https://npm.io/package/chai-bites

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2026-05-23
- 0.3.0 — 2026-05-23
- 0.2.0 — 2024-05-01
- 0.1.2 — 2021-12-13

## README

Fork of [chai-bytes](https://www.npmjs.com/package/chai-bytes) published as ESM with relaxed input types.

# Chai Assertions for Byte Arrays Equality

[![Build status][workflow-image]][workflow-url]
[![Code coverage][coveralls-image]][coveralls-url]
[![Code style][code-style-image]][code-style-url]
[![License][license-image]][license-url]

[workflow-image]: https://github.com/slowli/chai-bytes/workflows/Node.js%20CI/badge.svg?branch=master
[workflow-url]: https://github.com/slowli/chai-bytes/actions
[coveralls-image]: https://img.shields.io/coveralls/slowli/chai-bytes.svg
[coveralls-url]: https://coveralls.io/github/slowli/chai-bytes
[code-style-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg
[code-style-url]: https://github.com/Flet/semistandard
[license-image]: https://img.shields.io/github/license/slowli/chai-bytes.svg
[license-url]: https://opensource.org/licenses/Apache-2.0

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

## Basic Usage

```javascript
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:

- 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 `Uint8Array`s (e.g., it misses a substantial parts
of their methods).

## License

**chai-bytes** is available under [Apache-2.0 license](LICENSE).

[chai]: https://chaijs.com/

---
_Source: https://npm.io/package/chai-bites · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
