node-mocks
node-mocks copied to clipboard
Can't mock require.resolve() using mocks.loadFile()
The code I was testing relies on Node's built in require.resolve()
function, running it before the module is imported. Unfortunately, since this library replaces require()
and calls the module immediately before replacing custom mocks, I was unable to stub require.resolve()
using loadFile()
's mocks
or globals
arguments.
For anyone also having this problem, I'm using proxyquire (which is similar to mocks.loadFile()
) as a workaround.