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.

Enzyme `mount` cause error when renders react-select

See original GitHub issue

Hello!

I have problem with testing latest (3.0.5) version of react-select

code

...
import Select from 'react-select'

const Product = () => (
  <Select options={[]} onChange={() => null} />
);

export default connect(() => {}, () => {})(Product);

test suite

import { mount } from 'enzyme';

...
    const wrapper = mount(
        <IntlProvider locale="en" messages={{}}>
            <Provider store={store}>
                <Product />
            </Provider>
        </IntlProvider>
    );
 ...

When enzyme try to mount component with Select, console displays TypeError: Cannot read property 'registered' of null

It’s just FYI. In react-select v2.4.4 all is ok.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
k1462015commented, Dec 16, 2019

Based on the error, it seems we need to make sure a CacheProvider is available:

import createCache from "@emotion/cache";
import { CacheProvider } from "@emotion/core";

const cache = createCache();

function withCacheProvider(
        children: React.ReactNode,
) {
        return (
            <CacheProvider value={cache}>
                {children}
            </CacheProvider>
        );
}

const component = mount(withCacheProvider(
     (
         <ComponentUnderTestThatUsesReactSelect />
     ),
));

That got all of my tests running without needing to downgrade my react-select version, however, may not be the best solution.

I did need to add emotion as a dependency, yarn add emotion

2reactions
lbonatti89commented, Oct 4, 2019

Same issue here. Someone???

I have 3.0.8 version and the problem still happen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing React Select component - Stack Overflow
Test 1 : should render without errors. I render the component. I search for the placeholder to be present. Test 2 : should...
Read more >
Testing with Jest and Enzyme in React — Part 4 (shallow vs ...
The reason for this is, mount renders the full DOM including the child components in the parent component. So, this has fully rendered...
Read more >
Continuous integration for React applications using Jest and ...
Learn how to implement continuous integration for React applications using Jest and Enzyme.
Read more >
Testing a Custom Select with React Testing Library
One of the questions that come up more often is how to test a custom select component. By custom select I mean a...
Read more >
[Solved]-Testing React Select component-Reactjs
[Solved]-Testing React Select component-Reactjs · Test 1 : should render without errors · Test 2 : should call onChange when the first option...
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