【发布时间】:2022-06-18 02:06:43
【问题描述】:
我的模拟 utilFunction 没有被使用,并且将日志记录添加到工厂函数表明它从未被调用过。我已经尝试搜索 jest.mock not working with relative paths 并且 jest.mock 没有被 Typescript 调用,认为它可能与 JS 测试和 TS 源代码的混合或源中使用的不同模块路径有关vs 测试代码。
正在测试的代码:
// src/foo/fooModule.ts
import { utilFunction } from '../util'
export const foo = () => {
return utilFunction()
}
测试代码:
// test/fooModule.test.js
const { foo } = require('../src/foo/fooModule')
jest.mock('../src/util', () => {
return { utilFunction: () => 'mocked' };
});
describe('fooModule tests', () => ...)
【问题讨论】:
标签: javascript typescript jestjs ts-jest