I'm facing an issue where my mocked utilFunction
is not being utilized. Upon adding logging to the factory function, it becomes apparent that the function is never called. I have attempted to troubleshoot by searching for reasons such as jest.mock not working with relative paths and jest.mock not being called for Typescript tests. My suspicion is that this problem may be tied to the combination of JS tests and TS source code, or possibly due to discrepancies in module paths between the source and test code.
Here is the relevant code:
// src/foo/fooModule.ts
import { utilFunction } from '../util'
export const foo = () => {
return utilFunction()
}
And here is the test code:
// test/fooModule.test.js
const { foo } = require('../src/foo/fooModule')
jest.mock('../src/util', () => {
return { utilFunction: () => 'mocked' };
});
describe('fooModule tests', () => ...)