Skip to content

fent/node-muk-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

muk-require

Build Status Depfu codecov

muk

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