我正在尝试用 jest 对实用程序文件(util.js)进行单元测试,该文件看起来像,
// 实用程序.js
import { something } from '@whatever/nothing';
export const myMethod = (parameter) => {
if (!something ) return 0;
return something.length + parameter.length;
};
Run Code Online (Sandbox Code Playgroud)
// utils.test.js
import { myMethod } from '../utils';
test('myMethod', () => {
expect(myMethod('whatever').toEqual(12);
});
Run Code Online (Sandbox Code Playgroud)
某物是用“temp”值导出的模块。
当我运行测试文件时,某些内容总是未定义并最终返回0. 在测试文件中模拟模块“ ”something并使其在测试运行中可用的正确方法是什么?