The `assertion-error` package provides standardized `AssertionError` and `AssertionResult` classes, primarily designed for JavaScript and TypeScript test and validation frameworks. As of its current stable version `2.0.1`, it offers a robust way to represent both assertion failures and successes within a consistent `Result` interface. The library maintains a steady, though not rapid, release cadence, with significant updates like the `v2.0.0` rewrite to modern TypeScript and ES6 classes. A key differentiator is the inclusion of `AssertionResult`, which allows functions to explicitly return successful assertion outcomes alongside `AssertionError` for failures, both implementing a common `Result` interface with an `.ok` boolean property. This design streamlines error handling and result checking in testing utilities, providing a more structured approach than relying solely on exceptions. It supports both Node.js and Deno environments.
npm install assertion-errorVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing `AssertionError` and `AssertionResult`, creating instances, throwing `AssertionError`, and checking the `.ok` property on results.
Update import statements from `const AssertionError = require('assertion-error')` to `import { AssertionError } from 'assertion-error'` for ESM environments. For CommonJS, access the class via `require('assertion-error').AssertionError`.Adjust code to incorporate `AssertionResult` for explicit success handling where appropriate, and leverage the new `.ok` property for checking assertion outcomes regardless of success or failure.
In CommonJS environments, ensure you access the constructor as `require('assertion-error').AssertionError` (and `require('assertion-error').AssertionResult`).Always throw `AssertionError` instances and catch them in `try...catch` blocks. Return `AssertionResult` instances from functions where a successful (but explicit) assertion outcome is required. Check `instanceof Error` or the `.ok` property to differentiate.
Change `new require('assertion-error')` to `new (require('assertion-error').AssertionError)`.For CommonJS, use `const AssertionError = require('assertion-error').AssertionError;`. If you intend to use ESM, ensure your environment is configured for it (e.g., `"type": "module"` in `package.json`).Update `assertion-error` to version `2.0.0` or higher. Ensure your `tsconfig.json` is correctly set up to include `node_modules/@types` and that your IDE is picking up the latest type definitions.
No dependency data recorded yet.