muk-require
v1.2.0
Published
Mock dependencies.
Downloads
520
Readme
muk-require
Usage
Mock dependencies.
foo.js
const request = require('request');
module.exports = (url) => {
// Do something with request.
};
test.js
const request = require('request')
const mockedRequest = (url, options, callback) => {
// Log all requests.
console.log('Request made:', url);
request(url, options, callback)
};
const foo = muk('./foo', {
// Will overwrite all requires of "request" with our own version.
request: mockedRequest
});
You can also mock modules required with a relative path.
some/where/else/foo.js
const bar = require('./bar');
module.exports = () => {
// Do something with bar.
};
some/where/else/bar.js
exports.attack = 'sludge attack!';
test.js
const muk = require('muk-require');
const foo = muk('./some/where/else/foo', { './bar': 'hey!!' });
Install
npm install muk-require
Tests
Tests are written with mocha
npm test