tripwire

Test Support utilities, helpers, tools for testing in JavaScript and TypeScript.

View on GitHub

@nevware21/tripwire

JavaScript/TypeScript Test support utilities and assertion library

GitHub Workflow Status (main) codecov

Modules

Tripwire Core

npm version downloads downloads

Documentation

Core Assertion Typedoc

Feature Highlights

Feature Functions
Type Checking isObject, isArray, isString, isNumber, isBoolean, isFunction, isNull, isUndefined, isNaN, isFinite, typeOf, isInstanceOf, exists
Equality & Comparison equal, strictEqual, deepEqual, closeTo, isAbove, isBelow, isWithin, isAtLeast, isAtMost
Property Assertions hasProperty, hasOwnProperty, hasDeepProperty, nestedProperty, deepNestedProperty
Collection Operations includes, sameMembers, includeMembers, lengthOf, sizeOf
Change Tracking changes, increases, decreases - See Change/Increase/Decrease Assertions Guide
Error Testing throws, doesNotThrow
Extensibility createExprAdapter, addAssertFunc - See Expression Adapter Guide

Quick Start

Install the package:

npm install @nevware21/tripwire --save-dev

Recommended version range:

{
  "devDependencies": {
    "@nevware21/tripwire": ">= 0.1.4 < 2.x"
  }
}

Basic Usage

import { assert, expect } from '@nevware21/tripwire';

// Assert style - quick and direct
assert.equal(1 + 1, 2);
assert.isString("hello");
assert.deepEqual({ a: 1 }, { a: 1 });

// Expect style - fluent and readable
expect(1 + 1).to.equal(2);
expect("hello").to.be.a.string;
expect({ a: 1 }).to.deep.equal({ a: 1 });

Shim Chai

npm version downloads downloads

Documentation

Chai Shim Typedoc

Quick Start

Install the package:

npm install @nevware21/tripwire-chai --save-dev

Recommended version range:

{
  "devDependencies": {
    "@nevware21/tripwire-chai": ">= 0.1.4 < 2.x"
  }
}

Migration from Chai

Migrating from Chai to Tripwire - Guide for upgrading from Chai.js

Step 1: Update your imports

- import { assert } from 'chai';
+ import { assert } from '@nevware21/tripwire-chai';

Step 2: Run your tests

Most assert.* functions should work immediately.

Step 3: Update error message tests (if needed)

Error messages differ from Chai - use regex for flexibility:

- assert.throws(() => fn(), "exact chai message");
+ assert.throws(() => fn(), /error message/);

What’s Supported

The shim implements the Chai v5.x assert API including:

What’s NOT Supported

When to Use Core Tripwire

Consider migrating to @nevware21/tripwire for: