3 ms·
I just added snapshot tests to a project (yesterday!), in preparation for validating a major refactor. They’re invaluable now, and helped me catch two very impo
by eyelidlessness 4y ago
I just added snapshot tests to a project (yesterday!), in preparation for validating a major refactor. They’re invaluable now, and helped me catch two very important but very subtle regressions I couldn’t have expected to test. The output isn’t directly visible, it’s just plain markup which gets styled by downstream users/libraries. And there’s a strong expectation that it’s stable, which makes refactoring especially risky.
Now, I can’t predict whether the snapshots will remain valuable over the long term. I expect they won’t, but mainly because I’d like to see this library eventually fade away and its responsibilities move into its primary downstream target. But that may take years, it took nearly two years to get to this refactor which will help enable that. I’m betting the snapshots will be equally valuable whenever that goal becomes possible. In the meantime, they’re my best assurance that I can honestly tell people I believe the current work I’m doing is safe and correct.
I don’t think they’re right for every project or every testing scenario in a given project, but knowing when they are a great fit is important too.