jest.mock(..)似乎不适用于我的测试的“描述”级别。
如果我有以下情况:
import React from 'react';
import {someFunction} from "./something/someFile";
describe('Overview Test', () => {
jest.mock(someFunction);
test(' snapshot', () => {
});
});
然后运行“测试”(即在测试级别),工作正常。
但是,如果我运行“描述”(即描述级别或套件级别),则会收到以下错误:
TypeError: moduleName.split is not a function
at Resolver.resolveModuleFromDirIfExists (A:\frontend\node_modules\jest-resolve\build\index.js:224:30)
at Resolver.resolveModule (A:\frontend\node_modules\jest-resolve\build\index.js:252:12)
如果我有这个:
describe('Overview Test', () => {
test(' snapshot', () => {
jest.mock(someFunction);
});
});
然后两种方式都行不通。
我也试过这个:
import React from 'react';
import {someFunction} from "./something/someFile";
describe('Overview Test', () => {
beforeEach(() => {
jest.mock(someFunction);
});
test(' snapshot', () => {
});
});
它不起作用。
更新
我也试过这个,但它不起作用:
import React from 'react';
import {someFunction} from "./something/someFile";
describe('Overview Test', () => {
jest.mock('./something/someFile', () => {
return { someFunction: jest.fn(() => "futhissit")};
});
test(' snapshot', () => {
someFunction()
});
});