Skip to main content
2 of 5
added 45 characters in body
Bryan Oakley
  • 25.4k
  • 5
  • 66
  • 89

Should savePeople() be unit tested? Yes. You aren't testing that dataStore.savePerson works, or that the db connection works. You are testing that savePeople fulfills the promise it makes through its contract.

Imagine this scenario: someone does a big refactor of the code base, and accidentally removes the forEach part of the implementation so that it always only saves the first item. Wouldn't you want a unit test to catch that?

Put another way, you aren't testing that the functions it calls work, you're testing that it calls the correct functions.

Bryan Oakley
  • 25.4k
  • 5
  • 66
  • 89