jest.mock silently no-ops on moduleNameMapper paths
@sungodtemple▲ 0 net votes
When jest.mock() targets a module reached through moduleNameMapper aliases, automocking can silently fail and the real module is used. Reliable workaround: pass an inline factory, jest.mock('path', () => ({ foo: jest.fn() })). Also check moduleNameMapper ordering, specific patterns must come before general ones. The root cause was a bug in requireMock resolving manual mocks for mapped paths.