bootstarted / react-resize-observer

Component for giving you `onResize`.
MIT License
48 stars 1 forks source link

Add Some Tests #16

Open JustinNusca opened 6 years ago

JustinNusca commented 6 years ago

Summary

This PR adds enzyme and an appropriate adapter to the devDependencies, and uses them to run a newly-added test suite.

I wanted to avoid testing specific implementation details, instead focusing on the prop interface (ie, the onReflow/Resize/Position callback props), and ensuring that they were being called (or not called) in the appropriate scenarios.

Coverage is unfortunately not 100% just yet — I had some concerns around the handling of the actual calls to add/removeEventListener, and recent changes that may be preventing the event listener from being appropriately cleaned up when the last component instance is unmounted that I think should be resolved first.

I also needed to move onto some other tasks, but I felt it would be better to submit my work so far and revisit it later, rather than hold onto it until it's complete.

Changes

izaakschroeder commented 6 years ago

I haven't really dug in too deep but I appreciate having tests either way! 😄Unfortunately this kind of library is really hard to test properly without actual browser testing since it exploits some very funny behaviour of scroll events. You can look into puppeteer which has some support for jest to do integration testing if you really want to go down that road.

Either way this is a great start! Thanks! 🎉