thlorenz / proxyquireify

browserify >= v2 version of proxyquire. Mocks out browserify's require to allow stubbing out dependencies while testing.
MIT License
151 stars 24 forks source link

Proxyquiring a file that proxyquires a file does not work as expected #67

Open dash- opened 7 years ago

dash- commented 7 years ago

My attempt to create a testing fixture to simplify testing has failed, because the fixture would need to use proxyquire, and the fixture would need to be proxyquired into the test. This does not appear to work.

For example, the following will fail:

a.js

const b = require('b');
module.exports = {b};

b.js

module.exports = 'failed';

a.fixture.js

const proxyquire = require('proxyquire');
module.exports = proxyquire('./a', {b: 'success'});

a.test.js


const expect = require('expect');
const proxyquire = require('proxyquire');
const a = proxyquire('./a.fixture', {});
describe('test', () => { it('should succeed', done => {
  expect(a).to.be.equal('success');
  done();
})});
bendrucker commented 7 years ago

Can you submit this as a project I can run? Please don't use mocha or anything else that distracts from the behavior in question. And if/throw statement for the test file would be ideal.