node-mocks icon indicating copy to clipboard operation
node-mocks copied to clipboard

Can't mock require.resolve() using mocks.loadFile()

Open nickserv opened this issue 8 years ago • 0 comments

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.

nickserv avatar Dec 14 '16 01:12 nickserv