Before writing a unit test, visualize the code flow as a tree. Put the function under test at the root, then expand each application function it calls. Stop at external functions or functions that call nothing; those nodes are leaves. Calls inside anonymous functions still belong beneath the function containing them. section 6.2.1
Use the tree to decide where testing effort belongs:
- Cover lower-level functions with more cases because they tend to handle less complex data. section 6.6
- Keep upper-level tests minimal when their called functions already have unit-test coverage and are assumed to work. section 6.2.3
- For mutations, test the calculation-heavy function first; wrapper functions usually need fewer tests. section 6.4
From search flow to mutation
A search tree can begin at Library.searchBooksByTitleJSON and branch to Catalog.searchBooksByTitle, _.get, and JSON.stringify. A mutation tree begins at System.addMember, passes through Library.addMember, and reaches UserManagement.addMember, where the main state-changing behavior is tested. section 6.2.1 section 6.4
View the search-query call tree as a visual starting point for mapping a function’s dependencies. section 6.2.1
