npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sounisi5011/jest-binary-data-matchers

v1.2.1

Published

Custom jest matchers to test binary data

Downloads

276

Readme

@sounisi5011/jest-binary-data-matchers

Go to the latest release page on npm Supported Node.js version: ^12.17.x || 14.x || 15.x || 16.x || 17.x || >=18.x Tested with Jest Commitizen friendly Minified Bundle Size Details Install Size Details Dependencies Status Build Status Maintainability Status

Custom jest matchers to test binary data.

Installation

npm install @sounisi5011/jest-binary-data-matchers
yarn add @sounisi5011/jest-binary-data-matchers
pnpm add @sounisi5011/jest-binary-data-matchers

Setup

Add "@sounisi5011/jest-binary-data-matchers" to your Jest setupFilesAfterEnv configuration.

"jest": {
  "setupFilesAfterEnv": ["@sounisi5011/jest-binary-data-matchers"]
}

TypeScript

In addition to the steps above, add to the types flag in your tsconfig.json.

{
  "compilerOptions": {
    "types": ["@sounisi5011/jest-binary-data-matchers"]
  }
}

API

Byte size

Compare number of bytes. If the comparison fails, display the human readable byte size.

.toBeByteSize(expected: number | bigint | ArrayBuffer | SharedArrayBuffer | TypedArray | DataView)

Compare whether the number of bytes in received and expected are equal. If the comparison fails, display the human readable byte size.

expect(12).toBeByteSize(12);
expect(12n).toBeByteSize(12);
expect(new ArrayBuffer(12)).toBeByteSize(12);
expect(new Uint8Array(12)).toBeByteSize(12);
expect(Buffer.alloc(12)).toBeByteSize(12);
expect(Buffer.from('abcdefghijkl')).toBeByteSize(12);

expect(Buffer.from('abcdefghijkl')).toBeByteSize(12n);
expect(Buffer.from('abcdefghijkl')).toBeByteSize(new Uint8Array(12));
expect(Buffer.from('abcdefghijkl')).toBeByteSize(new Uint16Array(6));
expect(Buffer.from('abcdefghijkl')).toBeByteSize(new Uint32Array(3));

expect(13).not.toBeByteSize(12);
expect(11n).not.toBeByteSize(12);
expect(new ArrayBuffer(16)).not.toBeByteSize(12);
expect(Buffer.from('vore')).not.toBeByteSize(12);

.toBeGreaterThanByteSize(expected: number | bigint | ArrayBuffer | SharedArrayBuffer | TypedArray | DataView)

Compare whether the number of bytes in received and expected are received > expected. If the comparison fails, display the human readable byte size.

.toBeGreaterThanOrEqualByteSize(expected: number | bigint | ArrayBuffer | SharedArrayBuffer | TypedArray | DataView)

Compare whether the number of bytes in received and expected are received >= expected. If the comparison fails, display the human readable byte size.

.toBeLessThanByteSize(expected: number | bigint | ArrayBuffer | SharedArrayBuffer | TypedArray | DataView)

Compare whether the number of bytes in received and expected are received < expected. If the comparison fails, display the human readable byte size.

.toBeLessThanOrEqualByteSize(expected: number | bigint | ArrayBuffer | SharedArrayBuffer | TypedArray | DataView)

Compare whether the number of bytes in received and expected are received <= expected. If the comparison fails, display the human readable byte size.

Binary data structure

.toBytesEqual(expected: ArrayBuffer | SharedArrayBuffer | TypedArray | DataView)

Compare whether the binary data of received and expected are equal. If the comparison fails, display the difference in binary data.

expect(Buffer.from('1234')).toBytesEqual(Buffer.from('1234'));
expect(new Uint8Array([0x31, 0x32, 0x33, 0x34])).toBytesEqual(Buffer.from('1234'));
expect(new Uint32Array([0x34333231])).toBytesEqual(Buffer.from('1234'));

expect(Buffer.from('123')).not.toBytesEqual(Buffer.from('1234'));
expect(Buffer.from('abcd')).not.toBytesEqual(Buffer.from('1234'));
expect(new Uint32Array([42])).not.toBytesEqual(new Uint8Array([42]));
expect(new Float32Array([42])).not.toBytesEqual(new Uint8Array([42]));