Pomax / react-onclickoutside

An onClickOutside wrapper for React components
MIT License
1.82k stars 187 forks source link

Support Jest Tests #191

Open athomann opened 7 years ago

athomann commented 7 years ago

It appears the user of findDOMNode prevents the ability to test components using the HOC. Is there a way to create the same functionality without findDOMNode. Use of refs? I'd be happy to help.

Pomax commented 7 years ago

Not really: this library is specifically for checking the DOM event chain in the browser, because not everything on a page is is managed by React, so it's not about "clicking on other components in the same app" but literally "clicking any HTML element in the DOM on this page, regardless of what put that HTML element there, and what -if anything- manages it" =)

This sounds like something to find a solution for in the Jest configuration(s), not something that can be fixed in this library.

interactivellama commented 6 years ago

We've ended up pulling everything out except this HOC and wrapping it inside the index.jsx. The component would be combobox/combobox.jsx or something and that's what we import in Jest unit tests. I've not tried switching it out for integration testing.

import onClickOutside from 'react-onclickoutside';
import Combobox from './combobox';

export default onClickOutside(Combobox);
Andarist commented 6 years ago

Also probably you could solve it with similar approach as here - https://github.com/andreypopp/react-textarea-autosize#how-to-test-it-with-jest-and-react-test-renderer