Comparing version 0.2.0 to 0.3.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10054
222
87
0