4 ms·
When possible, if I can implement something without tying it to React I will do that first, test that, and then make a React integration for it. User flows can
by JasonSage 2y ago
When possible, if I can implement something without tying it to React I will do that first, test that, and then make a React integration for it.
User flows can be written as sagas, or generators, or state machines—these get tested. Reifying a data object into some model that has a lot of derived getters or actions the presentation layer needs—this can be implemented and tested, then made available with a hook.
To me this is always the logical starting point because I can unit test or TDD, evaluate my assumptions about problems and solutions, and present conflicts to stakeholders, all without having to have the project up in the browser or writing problematic React tests.
When you have a component library that needs testing, or specific things need interaction testing, Storybook’s visual tests have been the easiest way to go. And if you’ve separated the logic out from the presentation as I’ve laid out, stories are easy to write because you’ve decoupled the presentation from the complicated bits from the start.