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.
Same issue here. Someone???
I have 3.0.8 version and the problem still happen.
Same issue with 3.0.8...
Same issue here - 3.0.8 version
Also the same issue with 3.0.8 version. Going to try vartemiev's solution "In react-select v2.4.4 all is ok."
...and that fixed the issue for me too.
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
Workaround by @k1462015 worked for me.
Thanks for workaround @k1462015, I'm now going to close this issue so we can keep on top of other issues in the repo.
However - if you'd like us to further investigate this if the workaround isn't good enough, please let me know.
I'm also getting this issue without using enyzyme. Will investigate further.
Most helpful comment
Based on the error, it seems we need to make sure a
CacheProvideris available: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
emotionas a dependency,yarn add emotion