12th Practical Class:
Unit Testing
Unit Testing: Jest
- Jest is JavaScript Testing Framework
- https://jestjs.io/
- already part of Create React App
Simple Unit Test
/sum.js
:
/__tests__/sum.js
:
run
yarn test
- it will find all tests in your project
React Testing Library
- https://testing-library.com/docs/react-testing-library/intro
- How to use React Testing Library Tutorial
change package.json
> "scripts"
> "test"
to:
src/organisms/__tests__/SingUpForm.js
:
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.
☠️ | ☠️ | ☠️ |
---|---|---|
☠️ | 🦠 | ☠️ |
☠️ | ☠️ | 🦠 |
generation x + 1
❔ | ❔ | ❔ |
---|---|---|
❔ | ☠️ | ❔ |
❔ | ❔ | ❔ |
Rule # 2
Any live cell with two or three live neighbors lives on to the next generation.
generation x
(n = 2,3)
☠️ | ☠️ | ☠️ |
---|---|---|
🦠 | 🦠 | ☠️ |
☠️ | 🦠 | 🦠 |
generation x + 1
❔ | ❔ | ❔ |
---|---|---|
❔ | 🦠 | ❔ |
❔ | ❔ | ❔ |
Rule # 3
Any live cell with more than three live neighbors dies, as if by overpopulation.
generation x
(n > 3)
🦠 | 🦠 | 🦠 |
---|---|---|
🦠 | 🦠 | 🦠 |
🦠 | 🦠 | 🦠 |
generation x + 1
❔ | ❔ | ❔ |
---|---|---|
❔ | ☠️ | ❔ |
❔ | ❔ | ❔ |
Rule # 4
Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
generation x
(n = 3)
☠️ | ☠️ | ☠️ |
---|---|---|
🦠 | ☠️ | ☠️ |
☠️ | 🦠 | 🦠 |
generation x + 1
❔ | ❔ | ❔ |
---|---|---|
❔ | 🦠 | ❔ |
❔ | ❔ | ❔ |
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