Posts

Showing posts from August, 2019

Unit testable components pt.4: Testing the Redux data flow

Testing actions within actions Testing redux is verbose. Sometimes it is even difficult. But it doesn't matter where you do it. It will always be challenging. The difference is that the DOM is irrelevant for my approach to testing. I use redux-mock-store to test my actions. No need for enzyme. One less moving part to deal with. That is the whole point of this testing style. Here is what a sample test would look like The action process const processHomeMount = () => async (dispatch, getState) => { try { const type = getState().home.topSearches.focusedDateRange const { endDate, startDate } = createPresentDateRange({ daysAgo: 100 }) await Promise.all([ dispatch(fetchPopularSearches({ type, limit: TOP_SEARCH_ENTRY_COUNT })),...

Unit testable components pt.3: Testing components

My approach to component testing There are multiple resources that show how to test components. When you read between the lines, they are actually describing their philosophy on how a component should be tested. My tests are basic and practical because my components are dumb My components have the following properties No api calls Small encapsulated components Minimal Redux actions As a consequence, my tests have the following principles Shallow mount component directly. Ignore Redux's connect higher order function (HOF) in test ...