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

Feature Highlights

Feature Functions
Type Checking isObject, isArray, isString, isNumber, isBoolean, isFunction, isNull, isUndefined, isNaN, isFinite, typeOf, isInstanceOf, exists
Equality & Comparison equal, strictEqual, deepEqual, deepStrictEqual, notDeepStrictEqual, 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, rejects, doesNotReject
Chaining and continues a chain after a called assertion (expect(5).is.number().and.is.above(1)); or passes when any of the given clause functions passes (expect(5).or(e => e.is.string(), e => e.is.number()))
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.8 < 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 });

Migration Guides

One guide per framework you are leaving. The Mocha, Karma and Jest guides end with a machine-readable JSON block for automated migrations.

Migrating from Node.js Native Assert

Migrating from Node.js Assert to Tripwire - Complete guide for migrating from Node.js native assert module

Key differences to be aware of: deepStrictEqual and notDeepStrictEqual match Node’s structural, type-strict behaviour (since v0.1.7 and v0.2.0 respectively), so they carry over unchanged. Two methods differ:

- assert.doesNotMatch(text, /pattern/);
+ assert.notMatch(text, /pattern/);

  await assert.rejects(fn, /error pattern/);  // unchanged

See the full migration guide for complete details and examples.

Test Runner, CLI & Configuration

Test Runner, CLI & Configuration Guide - Running the tripwire CLI against node/browser/worker targets, every CLI flag and .tripwirerc config field, file discovery, coverage, and hook failures (--fail-on-hook).

npx tripwire --target browser --reporter spec,xunit "test/**/*.test.ts"

Related:

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.8 < 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: