因此,在寻找问题的答案的过程中,我发现了以下信息:开玩笑:如何全局模拟node-uuid(或任何其他导入的模块)
我已经尝试了答案,但似乎无法正确使用它,因为它给了我未定义的错误。我是测试领域的新手,所以请原谅任何重大错误:
这是我的第一个方法
const mockF = jest.mock('uuid');
mockF.mockReturnValue('12345789');
Run Code Online (Sandbox Code Playgroud)
但是它无法识别功能。
我尝试了“ mockF.mockReturnValue不是一个函数”。
然后我尝试按照帖子的建议进行手动模拟,但似乎无法使其正常工作,您能帮我吗?谢谢
这是整个测试是否有帮助:
const faker = require('faker');
const storageUtils = require('../../storage/utils');
const utils = require('../utils/generateFile');
const { generateFileName } = storageUtils;
const { file } = utils;
test('should return a valid file name when provided the correct information', () => {
// ARRANGE
// create a scope
const scope = {
type: 'RECRUITER',
_id: '987654321',
};
// establish what the expected name to be returned is
const expectedName = …Run Code Online (Sandbox Code Playgroud)