Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

muk

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

muk - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

2

lib/method.js

@@ -18,3 +18,3 @@ // keep track of mocks

});
obj[key] = method || function() {};
obj[key] = method === undefined ? function() {} : method;
};

@@ -21,0 +21,0 @@

@@ -5,3 +5,3 @@ {

"keywords": ["test", "mock", "dependency"],
"version": "0.2.0",
"version": "0.3.0",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

# muk [![Build Status](https://secure.travis-ci.org/fent/node-muk.png)](http://travis-ci.org/fent/node-muk)
![muk](http://cdn.bulbagarden.net/upload/7/7c/089Muk.png)
# Usage
Mock an object's methods.
Mock dependencies.
```js
var fs = require('fs');
var muk = require('muk');
muk(fs, 'readFile', function(path, callback) {
process.nextTick(callback.bind(null, null, 'file contents here'));
});
```
Restore all mocked methods after tests.
```
muk.restore();
fs.readFile(file, function(err, data) {
// will actually read from `file`
});
```
Mock dependencies too.
**foo.js**

@@ -51,3 +32,3 @@ ```

**foo.js**
**some/where/else/foo.js**
```js

@@ -61,8 +42,34 @@ var bar = require('./bar');

**some/where/else/bar.js**
```js
exports.attack = 'sludge attack!';
```
**test.js**
```js
var foo = muk('./foo', { './bar': 'hey!!' });
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'));
});
```
Restore all mocked methods after tests.
```
muk.restore();
fs.readFile(file, function(err, data) {
// will actually read from `file`
});
```
# Install

@@ -69,0 +76,0 @@

@@ -28,3 +28,2 @@ var muk = require('..');

muk(fs, 'mkdir', mkdirMock);
assert.equal(fs.readFile, readFileMock, 'object method is equal to mock');

@@ -49,1 +48,21 @@ assert.equal(fs.mkdir, mkdirMock, 'object method is equal to mock');

});
describe('Mock property', function () {
var config = {
enableCache: true,
delay: 10
};
it('Contains original property', function () {
assert.equal(config.enableCache, true, 'enableCache is true');
assert.equal(config.delay, 10, 'delay is 10');
});
it('Property are new after mocked', function () {
muk(config, 'enableCache', false);
muk(config, 'delay', 0);
assert.equal(config.enableCache, false, 'enableCache is false');
assert.equal(config.delay, 0, 'delay is 0');
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc