@nevware21/tripwire
JavaScript/TypeScript Test support utilities and assertion library
Modules
Tripwire Core
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, 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
Documentation
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:
- Basic assertions:
equal,strictEqual,deepEqual,isOk,isTrue, etc. - Type checking:
isObject,isArray,isString,isNumber,isBoolean,isFunction, etc. - Comparisons:
isAbove,isAtLeast,isBelow,isAtMost,closeTo - Properties:
property,deepProperty,nestedProperty,ownPropertywith value checks - Collections:
include,deepInclude,members,sameMembers,keys - Changes:
changes,increases,decreaseswith delta tracking - Errors:
throws,doesNotThrow - Object state:
isExtensible,isSealed,isFrozen,isEmpty
What’s NOT Supported
expectAPI - Use core tripwire insteadshouldAPI - No plans to implement- Plugins -
use()function not available
When to Use Core Tripwire
Consider migrating to @nevware21/tripwire for:
- Better error messages
- Fluent
expectsyntax - New features and improvements
- Long-term maintenance