test-helpr

raw JSON →
0.3.2 verified Sat May 09 auth: no javascript maintenance

A collection of miscellaneous test helper functions for Node.js, version 0.3.2. Provides lightweight utilities to simplify common testing patterns. The package is minimal and has no dependencies, making it easy to integrate. It is released sporadically, with no active development since 2020. Differentiators include simplicity and zero external dependencies compared to larger testing libraries like Jest or Mocha.

error Cannot find module 'test-helpr'
cause Package not installed or ESM-only require attempt.
fix
Run npm install test-helpr and use import syntax.
error The requested module 'test-helpr' does not provide an export named 'default'
cause Trying to default import from a package that only has named exports.
fix
Use import { ... } from 'test-helpr' instead of import testHelpr from 'test-helpr'.
error Error: Cannot find module 'test-helpr' require() of ES Module
cause Using require() with an ESM-only package.
fix
Replace require() with import, or use dynamic import() if necessary.
breaking ESM-only since version 0.3.0; CommonJS require() no longer supported.
fix Use import syntax: import { ... } from 'test-helpr'
deprecated Functions may have undocumented side effects; no active maintenance.
fix Consider migrating to a more actively maintained library like sinon.
gotcha mockFn does not reset calls between test cases; manual reset needed.
fix Reset mock.calls = [] in beforeEach or afterEach.
npm install test-helpr
yarn add test-helpr
pnpm add test-helpr

Demonstrates importing and using three main helpers: createMockContext, mockFn, and stubConsole.

import { createMockContext, mockFn, stubConsole } from 'test-helpr';

// Create a mock context
const ctx = createMockContext();

// Create a mock function
const mock = mockFn();
mock('arg');
console.log(mock.calls); // [['arg']]

// Stub console.log
const restore = stubConsole();
console.log('test');
console.log(console.output); // ['test']
restore();