I'm trying to test my antd application with react testing library, but I keep getting this error:
TypeError: Cannot read property 'addListener' of undefined
Im using a custom render but the error seems to be coming from the 'render' method.
const customRender = (ui, options) => render(ui, { wrapper: TestingWrapper, ...options }) ^
I´m even using the same versions of react and react-dom (which seems to be a common issue with rtl).
"react": "17.0.1", "react-dom": "17.0.1",
The problematic component seems to be this:
import React, {
lazy,
Suspense
} from 'react';
import List from 'antd/lib/list';
const Stories = (props) => {
return(
<div className="stories-container">
<div>
<h1 className="StoriesTitle">Stories</h1>
</div>
<div className="StoryListContainer">
<Suspense fallback={<Spin />}>
<List
itemLayout="vertical"
size="default"
pagination={pagination}
dataSource={stories}
renderItem={item =>
<StoryItem
item={item}
deleteFn={onDelete}
loggedIn={loggedIn}
stories={stories}
/>
}
/>
</Suspense>
</div>
</div>
);
}
It seems to error out in the module 'antd/lib/_util/responsiveObserve' which is a part of antd's List component. Taking that component out makes the test work (though obviously I don't want to remove it from my application).