Registry / testing / babel-plugin-mock-imports

babel-plugin-mock-imports

JSON →
library1.2.0jsnpmunverified

Babel plugin for redirecting import statements to different locations. Current version 1.2.0, first released as 0.0.1. Key differentiator: simple configuration via RegExp patterns, useful for mocking modules or aliasing imports. Stable API with minimal changes.

npm install babel-plugin-mock-imports
INSTALL
IMPORT
SIG · BABEL-PLUGIN-MOCK-
B
babel-plugin-mock-imports
testingjavascriptv1.2.0
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.

plugin
['mock-imports', { redirects: [...] }] in .babelrc or babel.config.js
require('babel-plugin-mock-imports')
The plugin is a Babel plugin and should be listed in Babel configuration, not directly required in code.
redirects
pattern: '.(svg)$', location: 'path/to/mock'
pattern: /.svg$/
Pattern is a string that will be passed to RegExp constructor, not a RegExp literal.
type definition
No official type definitions; use @types/babel__core for general Babel types.
Plugin does not ship TypeScript types. For Babel config typing, use @types/babel__core.

Redirects all .svg imports to a mock component.

module.exports = { plugins: [ ['mock-imports', { redirects: [ { pattern: '.svg$', location: 'path/to/mocked/react/component' } ] }] ] };
Debug
Known issues
gotchaPattern strings are evaluated as RegExp; special characters must be escaped correctly.
fix
Escape regex special characters in pattern strings, or use strings that are safe for RegExp.
affects: >=0.0.1
gotchaPlugin replaces import source strings but does not transform default/namespace imports; ensure mock modules export the same interface.
fix
Ensure mock modules export the same symbols as the original modules.
affects: >=0.0.1
Errors
Common errors & fixes
Error: .babelrc plugin is not a string or object/fn
Plugins array item is incorrectly formatted.
fix
Use an array: ['mock-imports', { redirects: [...] }]
TypeError: Cannot read property 'redirects' of undefined
Plugin options object is missing or incorrect.
fix
Ensure options object has 'redirects' array.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
babel-plugin-mock-imports — npm install babel-plugin-mock-imports · libregistry