Posts

Showing posts from July, 2019

Unit testable components pt.2: Redux and separation of concerns

Use global state management, like Redux Production size codebases are completely unmaintainable if local component state is exclusively used. Don't even try. React +16.3 introduced their own global state management system, the context api. But even then, I find it to be lacking base functionality. If you want those niceties, I don't think you should reinvent the wheel when redux is so functionality-rich with a huge open source community that backs it. I use the features you get from redux to keep my components virtually free of business logic. Opinion: Thunk is the only Redux middleware needed There is a lot of middleware out there, but I find redux-thunk to be more than adequate for my needs....

Unit testable components pt.1: Overview

Bad tests are worse than no tests This code should be changed or refactored, but that would mean I have to update my tests... Testing UI behavior is really hard, and you can get lulled into writing sloppy tests. Sloppy tests are unmaintainable and encourage "behavior locking". It's a problem that only grows as time goes on. Testing React components is hard Frontend testing requires, in one form or another, a mocked DOM, which is a beast in its own rite. Your tests can't be run like a basic function, because the true environment is the browser. Which is what enzyme was created for. It's a mandatory supplement to jest for component testing. C...