API Reference
proxyquire
Overrides require dependencies during unit tests without modifying the module under test.
Official Documentation ↗CompatibilityThis documentation covers version
v2.1. Check the official docs for the latest API surface.Installation
npm
npm install --save-dev proxyquireMethods
No methods match this filter.
proxyquire loads a module while substituting its imports, making isolation possible without a DI framework.
Key Features
- Per-test dependency stubbing
- noCallThru controls passthrough behavior
- Works with CommonJS require graphs
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
API reference evidence
Fetched from official sources on 2026-11-08T17:51:50+08:00 via WebFetch https://raw.githubusercontent.com/thlorenz/proxyquire/master/README.md.
proxyquire→ signature from https://raw.githubusercontent.com/thlorenz/proxyquire/master/README.md; official text: “proxyquire({string} request, {Object} stubs)”proxyquire.noCallThru→ signature from https://raw.githubusercontent.com/thlorenz/proxyquire/master/README.md; official text: “var proxyquireStrict = require(‘proxyquire’).noCallThru();”proxyquire.noPreserveCache→ signature from https://raw.githubusercontent.com/thlorenz/proxyquire/master/README.md; official text: “var proxyquire = require(‘proxyquire’).noPreserveCache();”
FAQ
- Why did my stub not take effect?
- The stub key must match the exact module string used in require, including relative paths. A mismatch silently keeps the real dependency.
- Does it work with ESM?
- No. proxyquire relies on CommonJS require. For ESM use dependency injection or module mocking from the test runner instead.
- When should I avoid proxyquire?
- When the module can be designed for injection instead. Explicit parameters are clearer than substituting an import graph.
Report a problem with this API docOpens a pre-filled issue on GitHub.