Node.js Testing

Testing protects your Node code from regressions. Keep tests close to behavior and run them often.

Checks

  • Verify one function with a known input and output.
  • Check one server route returns the expected status.
  • Test one async path with a predictable result.

Package scripts

{
  "scripts": {
    "test": "node test.js"
  }
}

Practice

  1. Add one test script to a small project.
  2. Make the test fail once, then fix the code.
  3. Write one sentence about what the test proved.