- Practice writing tests with Jest
- Catch any bugs in your project's object-oriented code
Now that you've put your frontend together, you'll write Jest tests to ensure your code works as expected.
Don't worry about testing React components - today you'll focus on testing the functions you've written.
- Go back to your User.js and Events.js files, and refamiliarize yourself with what you did there. We will be adding Jest tests for each function.
- Create a test folder, and start with 2 new files: one for Users and one for Events. Our Jest outline can remind you how to structure this.
- In your project root, run
jest
(it will start your tests). - A lot of them will fail or not be found, and your challenge is to fix them. Debug why the tests are failing and update the Jest code and/or your classes to make the tests pass. Every time you make a fix, run
jest
again to check your tests. This might take a while but is good practice for debugging both your tests and your code. - When you get the existing tests working, add tests for other functions you have implemented.
- Add at least one more test of your choice. What else could be useful to test in your code?