reselect icon indicating copy to clipboard operation
reselect copied to clipboard

Add documentation about how to test

Open ccapndave opened this issue 11 years ago • 3 comments

It would be really useful to have a section in the readme with an example of how to write unit tests for selectors. The obvious strategy is to have two functions for every selector; the selector and the pure function:

export const getAddition = (a, b) => a + b // test this one
export const additionSelector = createSelector([ aSelector, bSelector ], getAddition);

However, this can be quite annoying because (at least in my app) the pure functions are almost always only used within the selector so it means having to figure out a naming strategy, be extra careful for typos, have a bigger API footprint, etc. However, if testing the selectors directly are we going to run into subtle problems with memoization or anything like that? Does testing selectors directly even work as a concept?

Any advice appreciated!

ccapndave avatar Aug 25 '15 07:08 ccapndave

I have been testing selectors directly. I'm currently in the middle of rewriting the documentation at the moment, I'll get my thoughts straight on this topic and add them as a section to the readme as suggested. Keep an eye on the 1.0.0_WIP branch in the next few days.

ellbee avatar Aug 25 '15 21:08 ellbee

:+1: Nice suggestion @ccapndave. I am currently wondering about how to approach this myself.

bvaughn avatar Aug 31 '15 19:08 bvaughn

I put something in the docs about how I test selectors. Feedback is welcome if anyone has a better approach.

ellbee avatar Sep 09 '15 20:09 ellbee