The `a` package provides a versatile mocking framework for JavaScript and TypeScript, designed to be used with any testing framework. It is currently stable at version 4.0.8, with recent updates including the addition of comprehensive TypeScript types in v4.0.7, indicating an active development cadence. Key differentiators include its ability to create both partial mocks (which fall back to the original function) and strict mocks (which throw on unexpected calls), alongside detailed argument expectation, advanced matching for arrays and objects, and control over repeat behaviors. This allows for precise control over test doubles, supporting TDD and BDD methodologies in unit testing scenarios. The framework provides flexible options for stubbing and verification of function calls.
npm install aVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating strict and partial mocks, expecting arguments, controlling call repeats, and handling unexpected calls.
Always define expectations for all possible call patterns or use `mock.ignoreAll().return(...)` for a wildcard match, or `repeatAny()` for infinite repeats.
Ensure that your expected object or array exactly matches the structure and values of the input you anticipate, or use `ignore()` for specific arguments if their value doesn't matter.
If a mock expectation should be valid indefinitely, explicitly chain `.repeatAny()` to it. Otherwise, ensure your test logic does not call the mock more times than expected.
Review the mock's `expect()` configurations. Ensure all valid call patterns are defined, or use `repeatAny()` if calls should be infinite. If it's a strict mock, ensure only expected arguments are passed.
Verify that `a` is imported as the default export (`import a from 'a';` for ESM or `const a = require('a');` for CommonJS). Check your `package.json` for `"type": "module"` if using ESM.No dependency data recorded yet.