question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't run unit test same as in the example docs

See original GitHub issue

When I run my test I see the next: image

Code of the test is pretty mush simple.

import React from 'react'
import { shallow } from 'enzyme';
import OrganizationSelect from './index';

it('renders Dashboard', () => {
  // Use the wrapped components
  const wrapper = shallow(<OrganizationSelect.WrappedComponent user={{ list: [] }} loading={{user: []}}/>);
  // const wrapper = shallow(<OrganizationSelect/>);
  expect(wrapper).toBe()
});

Code of the component

import React from 'react';
import { connect } from 'umi';
import { Select } from 'antd';
import styles from './index.less';

const { Option } = Select;

const OrganizationSelect = ({ dispatch, currentUser, loading, ...props }) => {
  const handleChange = async (code) => {
    await dispatch({
      type: 'user/setLastSelectedOrganization',
      payload: code,
    });
    await dispatch({
      type: 'user/fetchCurrent',
    });
  };
  if (!loading) {
    return (
      <Select
        className={styles.organizationSelect}
        defaultValue={
          currentUser.last_selected_organization
            ? currentUser.last_selected_organization.code
            : null
        }
        onChange={handleChange}
      >
        {currentUser.organizations.map(({ name, code }, i) => (
          <Option key={code} value={code}>
            {name}
          </Option>
        ))}
      </Select>
    );
  }
  return <></>;
};

export default connect(({ user, loading }) => ({
  currentUser: user.currentUser,
  loading: loading.models.user,
}))(OrganizationSelect);

How I can fix this error and make my test run? Can you help me, please? Many thanks for the answers in English!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

2reactions
chenshuai2144commented, Jul 13, 2021

我们很关注这个问题,但是它已经很长时间没有回应。我们会暂时关闭它 —— We are very concerned about this issue, but it has not responded for a long time. We will temporarily close it

0reactions
Lubyamcommented, Dec 5, 2020

the same issue. Unhandled Rejection (TypeError): (0 , _umi.connect) is not a function ./src/layouts/BasicLayout.tsx src/layouts/BasicLayout.tsx:174

171 | ); 172 | }; 173 | 174 | export default connect(({ global, settings }: ConnectState) => ({ 175 | collapsed: global.collapsed, 176 | settings, 177 | }))(BasicLayout); image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run unit tests with Test Explorer - Visual Studio (Windows)
Test Explorer can run tests from multiple test projects in a solution and from test classes that are part of the production code...
Read more >
Run tests | IntelliJ IDEA Documentation - JetBrains
To run all tests in a folder, select this folder in the Project tool window and press Ctrl+Shift+F10 or select Run Tests in...
Read more >
Should I document my unit test methods? - Stack Overflow
Agreed w/ Vinko: sometimes it doesn't work that well, like when you do data-driven tests, and use the same unit test template, passing...
Read more >
Unit testing | Replit Docs
Unit testing is great for more complicated testing scenarios. For example, when you need to test that functions return specific values based on ......
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
Basic example¶. The unittest module provides a rich set of tools for constructing and running tests. This section demonstrates that a small subset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found