I have an AProvider class that requires './b.provider' .
const BProvider = require('./b.provider'); class AProvider { static get defaultPath() { return `defaults/a/${BProvider.getThing()}`; } } module.exports = AProvider;
b.provider.js is next to a.provider.js and looks like
global.stuff.whatever = require('../models').get('Whatever'); // I didn't write this! class BProvider { static getThing() { return 'some-computed-thing'; } } module.exports = BProvider;
In my test, I use proxyquire to extract ./b.provider as follows:
import { expect } from 'chai'; import proxyquire from 'proxyquire'; describe('A Provider', () => { const Provider = proxyquire('../src/a.provider', { './b.provider': { getThing: () => 'b-thing' }, }); describe('defaultPath', () => { it('has the expected value', () => { expect(Provider.defaultPath).to.equal('defaults/a/b-thing') }); }); });
However, when I run the BProvider test, the actual './b.provider' still required, and not the stub and BProvider reference to global.stuff.whatever gives an error.
Why is this not working?
source share