alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.13k stars 319 forks source link

Replace snapshot tests #1152

Open penx opened 5 years ago

penx commented 5 years ago

I am pretty sure that the use of Jest snapshots in govuk-frontend is mainly due to their ease of implementation - and could be replaced by tests that use axiom to look for specific properties of the render output.

Using snapshots means that if a change is made that introduces a white space change or changes the html attribute order, according to the snapshot test this is a failure - generally I would say this is a false positive.

This is of particular concern when developing a port and wanting to ensure the port adheres to all of the same unit tests for templates - the snapshots files are hard to manage across projects and raise false positives.

Related:

Some articles against snapshot testing:

From the first link

We've found that in practice, snapshot tests end up making assertions that aren't clearly represented in the test output. The assertion tries to focus on a very specific behavior or attribute, but because the test renders the entire component, it regularly leads to tests that fail for unrelated reasons. It's not immediately clear whether something is actually wrong, especially for developers who are unfamiliar with the component.

NickColley commented 5 years ago

We're generally using snapshots tests to sanity check any composed components that we pass params to, so we're not duplicating the testing we've already done in the specific component tests.

Worth a look to see if we can do this in a friendlier way for porting.