Registry / testing / can-test-helpers

can-test-helpers

JSON →
library1.1.4jsnpmunverified

CanJS Test Helpers is a utility package designed to provide common testing functions specifically for modules within the CanJS ecosystem. Currently at version 1.1.4, its primary features include `willWarn` and `willError` for intercepting and asserting against `canDev.warn` and `canDev.error` calls, and `devOnlyTest` for defining tests that execute only in development environments. The package ensures compatibility with modern testing setups by requiring QUnit 2.x since version 1.1.4. Its release cadence is generally aligned with updates in the broader CanJS family of libraries, such as `can-log` and `can-util`, ensuring seamless integration. A key differentiator is its direct interaction with CanJS's internal development logging mechanisms, providing fine-grained control over testing expected warnings and errors, which is crucial for library maintainers and application developers building with CanJS.

npm install can-test-helpers
INSTALL
IMPORT
SIG · CAN-TEST-HELPERS
C
can-test-helpers
testingjavascriptv1.1.4
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.

devHelpers
import devHelpers from 'can-test-helpers/lib/dev';
const devHelpers = require('can-test-helpers/lib/dev');
The primary export is a default object containing `willWarn`, `willError`, and `devOnlyTest`.
willWarn
import devHelpers from 'can-test-helpers/lib/dev'; devHelpers.willWarn(...);
import { willWarn } from 'can-test-helpers/lib/dev';
Individual helpers are properties of the default `devHelpers` object, not direct named exports.
devOnlyTest
import devHelpers from 'can-test-helpers/lib/dev'; devHelpers.devOnlyTest(...);
`devOnlyTest` is a utility for QUnit that defines a test to run only in a development build.

Demonstrates how to use `willWarn` and `willError` helpers to intercept and assert against development warnings and errors in a CanJS context.

// For demonstration purposes, mock canDev if not in a full CanJS environment. // In a real CanJS app, 'can-log/dev/dev' would be imported or globally available. const canDev = { warn: (message: string) => console.warn(`canDev.warn: ${message}`), error: (message: string) => console.error(`canDev.error: ${message}`) }; import devHelpers from 'can-test-helpers/lib/dev'; // Example 1: Testing expected warnings const finishWarningCheck = devHelpers.willWarn("Something deprecated", (message, match) => { console.log(`Intercepted warning: "${message}" (matched: ${match})`); }); canDev.warn("Something deprecated"); canDev.warn("Another unrelated warning"); const matchedWarnings = finishWarningCheck(); console.assert(matchedWarnings === 1, `Expected 1 matched warning, got ${matchedWarnings}`); // Example 2: Testing expected errors const finishErrorCheck = devHelpers.willError(/critical error/i); try { // Simulate an error being caught and logged by canDev throw new Error("A critical error occurred!"); } catch (e) { canDev.error((e as Error).message); } const matchedErrors = finishErrorCheck(); console.assert(matchedErrors === 1, `Expected 1 matched error, got ${matchedErrors}`); console.log("Quickstart example completed. Check console output for assertions.");
Debug
Known issues
breakingcan-test-helpers v1.1.4 and above require QUnit 2.x. Projects using older QUnit versions will experience test failures or `QUnit` API incompatibility.
fix
Upgrade QUnit in your project to v2 or higher. Adjust any QUnit 1.x specific assertions if necessary.
affects: >=1.1.4
gotchaThe `willWarn` and `willError` helpers are designed to interact with `can-log/dev/dev`. For these helpers to function correctly, `can-log/dev/dev` must be installed and properly configured in your test environment, or `canDev` must be appropriately mocked.
fix
Ensure `can-log/dev/dev` is a dependency of your project and correctly imported or globally available where CanJS is used, or provide a mock `canDev` object with `warn` and `error` methods.
affects: >=1.1.0
Errors
Common errors & fixes
TypeError: QUnit.test is not a function
Your test environment is likely using an outdated QUnit version (e.g., QUnit 1.x) while `can-test-helpers` expects QUnit 2.x.
fix
Upgrade QUnit to version 2 or higher in your project's `devDependencies`. If using a test runner, ensure it's configured to use the updated QUnit.
TypeError: canDev.warn is not a function
The `canDev` object (from `can-log/dev/dev`) is not correctly imported, installed, or exposed in your test environment, preventing `can-test-helpers` from stubbing its methods.
fix
Verify that `can-log/dev/dev` is installed (`npm install can-log --save-dev`) and correctly imported or globally available in your test setup. If not running a full CanJS app, you might need to mock `global.canDev` with `warn` and `error` methods.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
can-test-helpers — npm install can-test-helpers · libregistry