File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change
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 `
You can’t perform that action at this time.
0 commit comments