|
2 | 2 |
|
3 | 3 | ## Philosophy
|
4 | 4 | * Test code is a first-class part of the deliverable, not an optional nice-to-have.
|
5 |
| -* When scopeing / estimating work: always factor in testing. |
6 |
| -* Untestable code = bad code. |
7 |
| -* Insufficent test coverage is better than no test coverage. |
8 |
| -* Additional history and guiding principles are in [this "manitesto" doc](https://bitbucket.org/blog/save-time-with-default-pull-request-descriptions) |
| 5 | +* When scoping / estimating work: always factor in testing. |
| 6 | +* Testability is an attribute of good code. Code that cannot be tested is a problem. |
| 7 | +* Insufficient test coverage is better than no test coverage. |
| 8 | +* Prefer [Use Case Coverage over Code Coverage](https://kentcdodds.com/blog/how-to-know-what-to-test) (no need for 100% code coverage). |
| 9 | +* Additional history and guiding principles are in [this "manifesto" doc](https://docs.google.com/document/d/1XWx0GZLndtPF4-cwBeHii85osRj0ROPrflBF3DAVewA/edit) |
9 | 10 |
|
10 | 11 | ## Best Practices & Standardization
|
11 | 12 |
|
12 | 13 | ### General
|
13 | 14 | * Organization of `scripts` in package.json:
|
14 |
| - - `test` = runs all unit tests + E2E tests in headless mode |
| 15 | + - `test` = runs all unit/integration/E2E tests in headless mode |
15 | 16 | - `test:watch` = same as `test` but with Jest in watch mode
|
16 |
| - - `cypress` = run cypress with the dashboard open |
| 17 | + - `cypress` = run Cypress with the [Cypress Test Runner](https://docs.cypress.io/guides/guides/command-line.html#cypress-open) |
17 | 18 | - `check-lint` = runs style lint, eslint, prettier
|
18 | 19 | - `lint` = same as `check-lint` but writes the changes (`--fix`)
|
19 | 20 | - `ci` = run EVERYTHING
|
20 |
| -* Try to minimize nesting and coupling. These make tests brittle and hard to maintain. |
| 21 | +* [Apply the AHA principle](https://kentcdodds.com/blog/avoid-nesting-when-youre-testing). Try to minimize nesting, coupling and over-abstraction. These make tests brittle and hard to maintain. |
21 | 22 |
|
22 | 23 | ### Jest
|
23 | 24 | * Unit test files for components should be siblings in the same directory with a `.test.js` suffix. Placing test code close to application code is intended to encourage testing and make it harder to forget.
|
24 |
| -* For the test name, prefer the `it('does something')` sytnax because it is more self-documenting and intuitive |
| 25 | +* For the test name, prefer the `it('should do something')` syntax because it is more self-documenting and intuitive |
25 | 26 | * Use `describe()` and `beforeEach` sparingly. They lead to nesting and coupling.
|
26 | 27 |
|
27 | 28 | ### Testing Library
|
|
30 | 31 | * We encourage using the `screen` object exported by Testing Library because the resulting idioms will be more similar in React and Vanilla JS projects. [1](https://testing-library.com/docs/queries/about#screen), [2](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen).
|
31 | 32 |
|
32 | 33 | ## Favorite Tools
|
33 |
| -* Unit testing: Jest + Testing Library |
| 34 | +* Unit/integration testing: Jest + Testing Library |
34 | 35 | * E2E testing: Cypress
|
35 | 36 |
|
36 | 37 | ## Resources
|
|
0 commit comments