Reputation: 1043
I'm trying to test that a button in a certain react component triggers a function in its parent component. I stumble upon my issue right when I import the component in my test file, so the test hasn't even run yet.
The component I import is a regular react component and is exported as:
export default connect(mapStateToProps, mapDispatchToProps)(Manager);
And in my test file I import it as:
import Manager from '../index.js';
When I run the test I get:
Target container is not a DOM element.
I know this is very little information to give but there is literally nothing else relevant as far as I can see. The component I'm testing does a bunch of things and has a render function. After a lot of reading I read that some people had a similar issue because they exported something in the same file that does ReactDOM.render
. Unfortunately, this does not apply to my problem.
Any ideas?
Upvotes: 0
Views: 2156
Reputation: 2849
You can set an additional export without connect
in your Manager
and then you'll be able to import it in your test file and test its behavior:
export default connect(mapStateToProps, mapDispatchToProps)(Manager);
export { Manager };
Then in your test file:
import { Manager } from 'your-path'; // now a named import without Connect
Upvotes: 0