9th Practical Class:
Unit Testing
The Goal: Game Of Life
Unit Testing: Vitest
- Vitest is a JavaScript Testing Framework
- vitest.dev
- Compatible with Jest
- TypeScript and JSX support out of the box
:
Simple Unit Test
:
-
run
- it will find all tests in your project
React Testing Library
- testing-library.com
- How to use React Testing Library Tutorial
- Common mistakes with React Testing Library
:
Game Of Life
For more information visit the Conway's Game of Life page at Wikipedia.
Rule # 1
Any live cell with fewer than two live neighbors dies, as if by underpopulation.
☠️ | ☠️ | ☠️ |
☠️ | 🦠 | ☠️ |
☠️ | ☠️ | 🦠 |
❔ | ❔ | ❔ |
❔ | ☠️ | ❔ |
❔ | ❔ | ❔ |
Rule # 2
Any live cell with two or three live neighbors lives on to the next generation.
☠️ | ☠️ | ☠️ |
🦠 | 🦠 | ☠️ |
☠️ | 🦠 | 🦠 |
❔ | ❔ | ❔ |
❔ | 🦠 | ❔ |
❔ | ❔ | ❔ |
Rule # 3
Any live cell with more than three live neighbors dies, as if by overpopulation.
🦠 | 🦠 | 🦠 |
🦠 | 🦠 | 🦠 |
🦠 | 🦠 | 🦠 |
❔ | ❔ | ❔ |
❔ | ☠️ | ❔ |
❔ | ❔ | ❔ |
Rule # 4
Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
☠️ | ☠️ | ☠️ |
🦠 | ☠️ | ☠️ |
☠️ | 🦠 | 🦠 |
❔ | ❔ | ❔ |
❔ | 🦠 | ❔ |
❔ | ❔ | ❔ |
All Rules:
Test Drivend Deveopment (TDD)
- Write Failing Test
- Fix Tests
- Refactor
repeat!
TDD Cycle
1. Write Failing Test
2. Fix Failing Test
(as fast as possible)
- change code so all tests passes
3. Refactor
- refactor code (or tests too)
- all tests must pass