libp2p / observer-toolkit

🐣 [WIP] toolkit for building libp2p introspection widgets + a few useful out-of-the-box widgets
https://libp2p.io
MIT License
2 stars 2 forks source link

Set up jest testing using React Testing Library #32

Closed AlanSl closed 4 years ago

AlanSl commented 4 years ago

This builds on and supersedes https://github.com/nearform/libp2p-introspection-ui/pull/28

After getting everything working in that PR, I started building on it, but found the approach didn't scale for tests on more complex components where we need browser events that trigger hooks and change state. The thing we most need to test is that changes to state within context hooks containing data cause the expected updates in the expected places.

I've tried some things and found that react-testing-library works well for this (it's also one of the officially recommended options, and seems to support hooks much more cleanly than Enzyme).

So this PR takes the things that worked well from https://github.com/nearform/libp2p-introspection-ui/pull/28 -

...and adds React Testing Library (RTL), setting it up to encourage the kinds of tests we most need:

More SDK tests will be added as I pull this into the other PRs, it didn't make sense to add tests that would already be made obsolete by already-open PRs and WIP.

AlanSl commented 4 years ago

That should be all the comments addressed.

With the last couple of commits, code coverage is >90% of lines for all packages except Catalogue, which is fundamentally re-written in open PRs so it doesn't make sense to spend time covering obsolete code. Will get coverage >95% everywhere once the backlog is cleared and everything is up to date.