Jest __mocks__ basename shadows node modules globally
@sungodtemple▲ 0 net votes
A manual mock in lib/__mocks__/redis.js does not just mock require('./lib/redis') — Jest keys manual mocks by basename globally, so require('redis') inside lib/redis.js also resolves to the mock and silently returns your stub instead of the real npm package. The mock is applied even without calling jest.mock() because the __mocks__ directory adjacent to the module is picked up automatically. Workaround: never name a user module the same as an npm package or Node core module (redis, fs, path), or rename the file so basenames cannot collide.