mikeyhogarth / cocktails

UI for browsing IBA cocktails
https://iba-cocktails.netlify.com/
GNU General Public License v3.0
112 stars 27 forks source link

Better snapshot tests #57

Open mikeyhogarth opened 5 years ago

mikeyhogarth commented 5 years ago

We have some snapshot tests, but theyr'e not particularly good - specifically;

We want snapshot tests, but cant' really get those on things like the cocktailItem without introducing enzyme to use its mount functionality, or introducing things like the react-router MemoryRouter functionaity into the tests.

Lets spend some time making this good :)

bolivier commented 5 years ago

Any particular reason you're interested in snapshot tests over unit tests with something like react-testing-library?

I haven't experimented with it before, but it should be possible to mock the modules that import those routing components and replace them with trivial implementations that don't really work, but are testable nonetheless.

mikeyhogarth commented 5 years ago

So when it comes to testing UIs, I find they become insanely brittle and so I prefer to test them with the ol' head cameras rather than being declarative about it. That said, the whole thing here is totally lacking in the test department and I know that needs to improve - this ticket was just to cover the fact that we want to have full snapshot coverage and right now we don't.

These tests have actually saved me from a few silly mistakes during development, despite being something I've not put too much effort into.

To clarify then: you are absolutely right, I need to add some unit tests for the UIs (I do have unit tests for the non-UI stuff) but this ticket is purely about snapshot tests.

bolivier commented 5 years ago

That testing lib I linked is supposed to be less brittle than most because it only lets you test things as if you were using the ol' head cameras. There's no testing internal state, most tests I've used it for don't even use css selectors. I can whip up a few tests with it and you can see how you like them, but I've found it immensely helpful for unit testing UIs. I've refactored huge chunks of stuff and not had to touch a single test, because it eschews testing internals.

mikeyhogarth commented 5 years ago

Cheers m8 :) I will take a look.