Registry / testing / power-assert

power-assert

JSON →
library1.6.1jsnpmunverified

Power Assert in JavaScript v1.6.1 (stable, released 2017). Provides descriptive assertion messages via the standard Node.js assert interface. No API is the best API – you only need assert(any_expression). Requires code transformation (via Babel, browserify, webpack, etc.) to generate detailed failure messages. Differentiated from chai/should by reusing the native assert module; you can swap require('power-assert') for require('assert') with zero API change. Works server-side and browser-side. Maintained by the original author but has been stable with infrequent releases.

npm install power-assert
INSTALL
IMPORT
SIG · POWER-ASSERT
P
power-assert
testingjavascriptv1.6.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import 'power-assert'; const assert = require('assert');
const assert = require('power-assert');
Import side-effects to augment assert module; then use native assert. This is the recommended pattern.
default
const assert = require('power-assert');
const assert = require('assert');
This works but less transparent; side-effect import is preferred.
assert
import assert from 'power-assert';
import { assert } from 'power-assert';
Named export is not available; use default import.

Usage with Babel: augment assert, then use native assert methods; power-assert provides detailed diffs.

// Install: npm install --save-dev power-assert babel-plugin-espower // .babelrc: { "plugins": ["babel-plugin-espower"] } // test.js import 'power-assert'; const assert = require('assert'); const a = [1, 2, 3]; const b = [1, 2, 3, 4]; assert.deepStrictEqual(a, b); // Without transformation: AssertionError [ERR_ASSERTION]: [1,2,3] deepStrictEqual [1,2,3,4] // With power-assert transformation: // assert.deepStrictEqual(a, b) // | | // | [1,2,3,4] // [1,2,3]
Debug
Known issues
gotchaWithout code transformation, power-assert falls back to normal assert output.
fix
Add a code transformation step (Babel plugin, browserify transform, webpack loader, etc.) to your build process.
affects: >=1.0.0
breakingIn v1.0.0, the API changed to require side-effect import (import 'power-assert') instead of requiring the module directly.
fix
Use import 'power-assert' at module top; still call require('assert') for assertions.
affects: >=1.0.0
deprecatedBower package is maintained but no longer updated; Bower itself is deprecated.
fix
Use npm to install power-assert.
affects: all
gotchapower-assert relies on AST transformation; test files must be transpiled before execution.
fix
Ensure test files are transformed via Babel, browserify, or other tools. Use babel-plugin-espower or eslint-plugin-espower as part of the build.
affects: >=1.0.0
gotchaWhen using mocha with power-assert, you must configure the test runner to perform transformation (e.g., require babel-register).
fix
Run mocha with --require babel-register and Babel config with babel-plugin-espower.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: assert(expression) is not a function
Importing power-assert incorrectly (e.g., using named import).
fix
Use `import 'power-assert'` as a side-effect import, not expecting named exports.
AssertionError [ERR_ASSERTION]: Expression is not truthy
power-assert transformation did not run; test code not transpiled.
fix
Add babel-plugin-espower to Babel config and run test with Babel.
Cannot find module 'power-assert'
power-assert not installed in node_modules.
fix
Run `npm install --save-dev power-assert`.
ReferenceError: require is not defined
Using `require('assert')` in ES module (type: module) environment.
fix
Switch to ES module import: `import assert from 'assert'` after `import 'power-assert'`.
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
empowerrequiredredefines assert methods for power-assert output
power-assert-formatterrequiredformats assertion error messages
espowerrequiredtransform library to instrument test code
Agent activity
4 hits · last 30 days
node
4
Resources
power-assert — npm install power-assert · libregistry