https://github.com/unjs/mocked-exports
https://github.com/unjs/mocked-exports
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/unjs/mocked-exports
- Owner: unjs
- License: mit
- Created: 2025-03-08T17:14:06.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-03-16T02:59:49.000Z (3 months ago)
- Last Synced: 2025-05-22T06:45:47.765Z (about 1 month ago)
- Language: TypeScript
- Size: 62.5 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# mocked-exports
[](https://npmjs.com/package/mocked-exports)
[](https://npm.chart.dev/mocked-exports)
[](https://codecov.io/gh/unjs/mocked-exports)Simple mocks (extracted from [unjs/unenv](https://github.com/unjs/unenv.git)).
Main usage of `mocked-exports` is to use them as **bundler aliases** to mock specific modules you don't want to end-up into your bundle.
```js
// Exports a dynamic mock proxy function
const proxy = require("mocked-exports/proxy");
import proxy from "mocked-exports/proxy";
import proxy from "mocked-exports/proxy/foo/bar/baz";// Exports a no-op frozen function
const noop = require("mocked-exports/noop");
import noop from "mocked-exports/noop";// Exports an empty frozen object
const empty = require("mocked-exports/empty");
import empty from "mocked-exports/empty";
```There are also extra variants of exports with `-mjs` or `-cjs` suffixes available if your mocking needs to force a specific format.
## Magic proxy
The `proxy` mock, is a nested deep proxy that tries to replace any dynamic nested access to an unknown object.
Examples: `proxy.foo.bar().xyz[1].then(() => {});`
For better debugging, you can use `proxy.__mock__('name')` to create a named instance.
## Development
local development
- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`## License
Published under the [MIT](https://github.com/unjs/mocked-exports/blob/main/LICENSE) license.
Made by [community](https://github.com/unjs/mocked-exports/graphs/contributors) 💛
![]()
---
_🤖 auto updated with [automd](https://automd.unjs.io)_