【问题标题】:TypeError: (0 , _umi.connect) is not a function while using jestTypeError: (0 , _umi.connect) 在使用 jest 时不是函数
【发布时间】:2020-08-26 12:03:49
【问题描述】:

我正在使用 jest 和酵素进行单元测试。但是我没有使用 react-redux,而是使用 umi 进行集中状态管理,但是在幕后它只使用 redux。现在,当我运行测试文件时,出现此错误

TypeError: (0 , _umi.connect) 不是函数

  101 | };
  102 | 
> 103 | export default connect(({ login, loading }: ConnectState) => ({
      |                ^
  104 |   userLogin: login,
  105 |   submitting: loading.effects['login/login'],
  106 | }))(Login);

  at Object.<anonymous> (src/pages/user/login/index.tsx:103:16)
  at Object.<anonymous> (src/pages/user/login/login.test.js:6:1)

这是我的测试文件

import { shallow, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });

describe('Login component tests', () => {
  let wrapper = shallow(
    <LoginContainer.WrappedComponent userLogin={{ status: '', message: '' }} />,
  );
})

【问题讨论】:

    标签: reactjs unit-testing jestjs enzyme


    【解决方案1】:

    我发现有一个已经打开的 github 问题。问题基本上出在 umi 库上。我使用了 react-redux 的 connect 方法,它工作得很好,但同时,为了使用 connect 方法而再拥有一个库是不合适的。我一直在使用它,直到它在 umi 中得到修复。

    https://github.com/umijs/umi/issues/5138https://github.com/ant-design/ant-design-pro/issues/6401

    【讨论】:

      猜你喜欢
      • 2021-05-01
      • 1970-01-01
      • 2018-02-10
      • 2021-12-26
      • 1970-01-01
      • 2020-03-03
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多