Closed grassick closed 8 years ago
I just merged your pull a little bit ago, but then it dawned on me that for sync tests, you can just override setTimeout
to execute the callback immediately. By doing that, binding to the window is not deferred, and so all of the async problems go away.
If you check out the test file, I've implemented it in the beforeEach
at the top. Only one test requires the bindings to be deferred, so in that case I restore the actual setTimeout
before running the test.
Oh, now I understand. The issue though is that my unit tests now need to use a hack on setTimeout even though they are testing some completely unrelated component which just happens to have react-onclickout buried deep inside. I can't really hack setTimeout for all my tests in that way.
Ah, I see. I hadn't thought about testing components that use the OnClickOut
component inside of them. Fair enough, I'll add that code back in. Sorry about that.
Published on npm @2.0.4
Thanks!
If a synchronous unit test is done that involves the component in any way, it will leave behind click events that will fire later. It's because the unmount is called before the deferred binding to the window.
The reason is that the binding to the window is deferred, but it should check that the component hasn't already unmounted before binding.