我试图模拟一个作为默认导出导出的异步函数,但我得到的只是TypeError: Cannot read property 'then' of undefined
我试图模拟的是config.js:
const configureEnvironment = async (nativeConfig) => {
return { await whatever() }
}
Run Code Online (Sandbox Code Playgroud)
我正在测试的文件是Scene.js:
import configureEnvironment from './config';
class Scene extends React.Component {
constructor(props) {
nativeConfig = {};
configureEnfironment(nativeConfig).then((config) => {
// Do stuff
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试文件是Scene.test.js:
let getScene = null;
const configureEnvironmentMock = jest.fn();
describe('Scene', () => {
jest.mock('./config', () => configureEnvironmentMock);
const Scene = require('./Scene').default;
getScene = (previousState) => {
return shallow( …Run Code Online (Sandbox Code Playgroud)