1.2.0 • Published 5 years ago

muk-require v1.2.0

Weekly downloads
46
License
MIT
Repository
github
Last release
5 years ago

muk-require

Build Status Dependency Status 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
1.2.0

5 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago