A unit test is a piece of a code (usually a method) that invokes another piece of code and checks the correctness of some assumptions afterward. If the assumptions turn out to be wrong, the unit test has failed. A unit is a method or function.

Use Inversion of Controll to make unit more testable.

filterFn gives us more controll on filter and make it easier to test.

function filter(array, filterFn) {
  let newArray = []
  for (let index = 0; index < array.length; index++) {
    const element = array[index]
    if (filterFn(element)) {
      newArray[newArray.length] = element
  return newArray

Tests show how to use your code. It can help to understand the code without documentation.

Tests should run in parallel. Why? It should speedup build. It enshure that tests are independent.

Compare Parralel and Single Thread test running


Parameterized Test to avoid code duplication



Draft notes