Skip to content

Commit 5dc85e3

Browse files
Add testing docs
1 parent 4e07cd4 commit 5dc85e3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/testing.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
How to write a UI unit test
2+
---
3+
1. See `src/tests/course.test.tsx` and my changes to `src/course/create-course-dialog.tsx`
4+
- We'll organize these the same way we'll organize interfaces: by scene/page/feature/namespace
5+
2. Add to an existing test file if testing the same namespace, or create a new test file. Import react and all that other stuff
6+
3. Import react-testing-library functions from `src/tests/test-utils.tsx`
7+
- This is our wrapper library that includes a custom render function to mock Apollo requests.
8+
4. Add a test(). Here are some handy functions:
9+
- `render()`: Render your component
10+
- `fireEvent`: This is the mocked user. Use it to mock `.click()` events, for example.
11+
- `screen.getBy...()`: This is called a query, used to grab UI components. Think of them like querySelectors.
12+
- The ones we'll use the most is probably `getByTestId` or `getByLabelText`
13+
- `expect()`: Basically our assert
14+
- RTL Docs for more: [react-testing-library](https://testing-library.com/docs/react-testing-library/cheatsheet)
15+
- List of expect() chains: [jest-dom](https://github.com/testing-library/jest-dom#table-of-contents)
16+
5. Add necessary `data-testid`'s to components that you want to be grabbable by the tests.
17+
6. Run `npm test`

0 commit comments

Comments
 (0)