用Jest模拟破坏了导入?

时间:2019-08-09 11:24:02

标签: jestjs

我正在尝试用Jest模拟销毁的导入。

组件中已破坏的导入:

import { getSomething } from 'utils/paymentUtils';

在测试中:

import React from 'react';
import { shallow } from 'enzyme';
import Component from 'components/Component';
import * as utils from 'utils/paymentUtils';

jest.mock('utils');

describe('Something', () => {
  let wrapper;    
  utils.getSomething.mockImplementation(() => 'Blah');

我得到的错误是:

  

无法从'Component.spec.js'中找到模块'utils'

1 个答案:

答案 0 :(得分:0)

您必须模拟模块本身,在这种情况下为utils/paymentUtils