thlorenz / proxyquire

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.
MIT License
2.75k stars 100 forks source link

Mock multiple required modules with proxyquire #121

Closed JustinDFuller closed 8 years ago

JustinDFuller commented 8 years ago

Hi,

Please forgive me if I've missed something, but I would like to use proxyquire to mock multiple modules, let me give an example.

// JS File: 

var one = require('one');
var two = require('two');

function doStuff(args){
    var thing = two(args);
    return one(thing);
}

module.exports.doStuff = doStuff;
// Test file

var doStuff = proxyQuire('./doStuff.js', [
  {'one': oneStub },
  {'two': twoStub }
]);

// do tests down here

While reading the docs and looking at examples it doesn't seem like proxyquire is set up to work like this. I've tried this in my test anyways and it didn't seem to work.

Any ideas?

Thanks!

bendrucker commented 8 years ago

Instead of an array one and two should be keys in the same object