# mocked-exports

Latest version **0.1.1** (published 2025-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocked-exports
pnpm add mocked-exports
yarn add mocked-exports
bun add mocked-exports
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2025-03-09 |
| First published | 2025-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Maintainers | pi0 |

## Links

- npm: https://www.npmjs.com/package/mocked-exports
- Repository: https://github.com/unjs/mocked-exports
- Homepage: https://github.com/unjs/mocked-exports#readme
- Issues: https://github.com/unjs/mocked-exports/issues
- npm.io page: https://npm.io/package/mocked-exports

## Recent versions

- 0.1.1 (latest) — 2025-03-09
- 0.1.0 — 2025-03-08

## README

# mocked-exports

<!-- automd:badges codecov color=yellow -->

[![npm version](https://img.shields.io/npm/v/mocked-exports?color=yellow)](https://npmjs.com/package/mocked-exports)
[![npm downloads](https://img.shields.io/npm/dm/mocked-exports?color=yellow)](https://npm.chart.dev/mocked-exports)
[![codecov](https://img.shields.io/codecov/c/gh/unjs/mocked-exports?color=yellow)](https://codecov.io/gh/unjs/mocked-exports)

<!-- /automd -->

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

<details>

<summary>local development</summary>

- 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`

</details>

## License

<!-- automd:contributors license=MIT -->

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) 💛
<br><br>
<a href="https://github.com/unjs/mocked-exports/graphs/contributors">
<img src="https://contrib.rocks/image?repo=unjs/mocked-exports" />
</a>

<!-- /automd -->

<!-- automd:with-automd -->

---

_🤖 auto updated with [automd](https://automd.unjs.io)_

<!-- /automd -->

---
_Source: https://npm.io/package/mocked-exports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
