Testing 

Main motivation 

* Ship with confidence

     Sanity / regression

* CI / CD

     Automated process

* Accountability

     Correlating feature tickets to bug issues and bug fixes

* Documentation

     Demonstrate how your code can and should be used

* More unit tests == less QA

     Shorter development cycles

Top level testing categories

* Manual tests
     Test interactions in various use cases manually (takes longer & cost more)

* Automated tests

    Checks your code features by running it in various use case scenarios

* Static Analysis

    Checks your code without running it  - eslint & Typescript

Automated tests 

* Unit tests
     Individual components and functions

* Integration tests

    Test a group of components

* End-to-end tests

    Test the  entire system in various use-case scenarios

* Load / Stress / performance testing

    Test the system behaviour under certain conditions

Unit testing

* Synchronous code  
    pure functions + parameters  -->>  expect a deterministic result

* Async code

   Supports callbacks, Promises and async/await syntax

* UI tests

    Test generated UI elements + interactivity (front-end)

* Snapshots testing

     Validate the UI didn't change after integrating new features (front-end)

What do we actually want to test?

What kind of Tools do we need?

* a framework to run our tests
     Run tests, setup & teardown, timeout configuration etc...

* Assertions vocabulary

    Provide a language API to write our actual tests assertions

* Mimic DOM & events

     Virtual DOM & user interaction simulations (front-end)

* Mocking

     Mock the unit external dependencies I/O

* Test coverage

     How much of our code base is covered by tests

Testing frameworks

* Mocha      Used to be the most popular, big ecosystem

* Jasmine    Similar to mocha, less popular

* Jest           The dominant tool for JS testing

* Ava           Used to be the future, run tests in parallel

* Tape         lean, tiny, simple & minimal configuration

compare on npm trends 

* vitest        Same jest api. faster. easier to config.

Assertion libraries

* Should.js 

* expect.js          

Mocking

* Jest

the unit external dependencies

Functions & modules

Mock network response

* Nock

* MSW

* Mirage

* Faker

Generate dummy data

React.js

Test coverage

* Included in Jest

React.js

Demo time!