# muk

> Mock object methods and dependencies.

Latest version **0.5.3** (published 2016-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install muk
pnpm add muk
yarn add muk
bun add muk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.3 |
| Published | 2016-12-05 |
| First published | 2012-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Roly Fentanes |
| Maintainers | fent, popomore |
| Keywords | test, mock, dependency |

## Links

- npm: https://www.npmjs.com/package/muk
- Repository: https://github.com/fent/node-muk
- Homepage: https://github.com/fent/node-muk#readme
- Issues: https://github.com/fent/node-muk/issues
- npm.io page: https://npm.io/package/muk

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.5.3 (latest) — 2016-12-05
- 0.5.2 — 2016-06-12
- 0.5.1 — 2016-06-12
- 0.5.0 — 2016-06-11
- 0.4.0 — 2015-09-17
- 0.3.2 — 2014-12-28
- 0.3.1 — 2013-07-04
- 0.3.0 — 2013-04-15
- 0.2.0 — 2012-11-02
- 0.1.2 — 2012-10-31
- 0.1.1 — 2012-10-30
- 0.1.0 — 2012-10-30

## README

# muk

[![Build Status](https://secure.travis-ci.org/fent/node-muk.svg)](http://travis-ci.org/fent/node-muk)
[![Dependency Status](https://gemnasium.com/fent/node-muk.svg)](https://gemnasium.com/fent/node-muk)
[![codecov](https://codecov.io/gh/fent/node-muk/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-muk)

![muk](muk.gif)

# Usage

Mock dependencies.

**foo.js**
```js
var request = require('request');

module.exports = function foo(url) {
  // do something with request
};
```

**test.js**
```js
var mockedRequest = function(url, options, callback) {
  // mock a request here
};

var foo = muk('./foo', {
  request: mockedRequest
});
```

You can also mock modules required with a relative path.

**some/where/else/foo.js**
```js
var bar = require('./bar');

module.exports = function() {
  // do something with bar
};
```

**some/where/else/bar.js**
```js
exports.attack = 'sludge attack!';
```

**test.js**
```js
var foo = muk('./some/where/else/foo', { './bar': 'hey!!' });
```

Comes with object method mocking too.

```js
var fs = require('fs');
var muk = require('muk');

muk(fs, 'readFile', function(path, callback) {
  process.nextTick(callback.bind(null, null, 'file contents here'));
});
```

Check if member has been mocked.

```js
muk.isMocked(fs, 'readFile'); // true
```

Restore all mocked methods after tests.

```js
muk.restore();

fs.readFile(file, function(err, data) {
  // will actually read from `file`
});
```


# Install

    npm install muk


# Tests
Tests are written with [mocha](http://visionmedia.github.com/mocha/)

```bash
npm test
```

# License
MIT

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