Categories
Basic JavaScript

Testing in JS

What is “Testing”?

We have expected result of our code, and testing is to make sure that the expectation is achieved, otherwise modification should be done. Instead of manually do it, we prefer to automate and simplify the process.

Why Test?

  • Get an error in case break code
  • save time
  • think about possible issues and bugs
  • integrate into build workflow
  • break up complex dependencies
  • improve code

Different Kinds of Tests

  • Fully isolated (testing one function): Unit Tests
  • With dependencies (testing a function that calls a function): Integration Tests
  • Full Flow (validating the DOM after a click): End-to-End (E2E) Tests
different kinds of tests

Testing Setup

  • Test Runner: execute your tests, summarize results. e.g. Mocha
  • Assertion Library: define testing logic and conditions. e.g. Chai
    • Jest = test runner + assertion library
  • Headless Browser: simulates browser interaction. e.g. Puppeteer

Leave a comment