Skip to content

Commit 0c1409e

Browse files
Merge pull request #11 from CPSECapstone/setup-tests
Setup tests
2 parents ff76894 + 143b319 commit 0c1409e

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
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`

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@material-ui/icons": "^4.11.2",
1717
"@material-ui/lab": "^4.0.0-alpha.58",
1818
"@testing-library/jest-dom": "^5.11.10",
19-
"@testing-library/react": "^11.2.6",
2019
"@testing-library/user-event": "^12.8.3",
2120
"@types/jest": "^26.0.22",
2221
"@types/node": "^12.20.7",
@@ -30,6 +29,7 @@
3029
"formik": "^2.2.6",
3130
"get-video-id": "^3.2.0",
3231
"graphql": "^15.5.0",
32+
"lodash": "^4.17.21",
3333
"react": "^17.0.2",
3434
"react-bootstrap": "^1.5.2",
3535
"react-dom": "^17.0.2",
@@ -77,9 +77,12 @@
7777
"@graphql-codegen/typescript-operations": "1.17.16",
7878
"@graphql-codegen/typescript-react-apollo": "2.2.4",
7979
"@graphql-typed-document-node/core": "^3.1.0",
80+
"@testing-library/dom": "^7.30.3",
81+
"@testing-library/react": "^11.2.6",
8082
"@types/react-router-dom": "^5.1.7",
8183
"@types/react-table": "^7.0.29",
8284
"@types/styled-components": "^5.1.7",
85+
"cypress": "^7.1.0",
8386
"es-to-primitive": "^1.2.1",
8487
"eslint": "^7.23.0",
8588
"eslint-config-airbnb-typescript": "^12.3.1",

src/App/App.test.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)