2

I am new in unit testing in reactjs. I tried to test my login component rendering For testing, i am using JEST and enzyme.

[This is the error, i am getting]

Test case code:

import React from 'react';
import { shallow } from 'enzyme';
import Login from './index'; // Introduce the corresponding React component

it('renders Login page', () => {
    const wrapper = shallow(<Login.WrappedComponent login={{ name: '' }} />);
})

i am using Real project with umi - https://ant.design/docs/react/practical-projects

can any one help me on this.

Tanuj Gupta
  • 286
  • 5
  • 20
  • I really wanted to build a project with ant design as well... but me being english & the lib being mainly documented in Chinese proved too difficult. What I can recommend for you is to search for `enzyme and redux connect`. As ant design / UMI uses redux internally... So you might have more luck trying to solve for that. – Rohan Büchner Jul 16 '20 at 13:13
  • This thread seems like there might be some solutions. https://github.com/enzymejs/enzyme/issues/1002. Mainly... "In your test, just extract the "pure" Component rather than the connected one" – Rohan Büchner Jul 16 '20 at 13:13
  • 1
    Thanks @RohanBüchner its working – Tanuj Gupta Jul 17 '20 at 09:30
  • Well done! Asked & Answered your own question :) – Rohan Büchner Jul 17 '20 at 11:33

1 Answers1

3

We can use connect from react-redux instead of umi. actually umi is also using react-redux inside of it.

Replace this line in your component :

import { connect } from 'umi' with import { connect } from 'react-redux'

Tanuj Gupta
  • 286
  • 5
  • 20