【问题标题】:Mock destructed import with Jest?用 Jest 模拟破坏导入?
【发布时间】:2019-12-17 03:14:51
【问题描述】:

我正在尝试使用 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”

【问题讨论】:

  • 你的组件和你的测试在同一个目录吗?
  • 尝试模拟相同的路径:jest.mock('utils/paymentUtils')

标签: jestjs


【解决方案1】:

您必须模拟模块本身,在本例中为 utils/paymentUtils

【讨论】:

    猜你喜欢
    • 2018-06-30
    • 2018-03-27
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2019-04-01
    相关资源
    最近更新 更多