Writing tests for my new job has been a big struggle for me recently. It feels like when I first got started programming, I knew what I wanted to do but I couldn't tell the computer how to get it done. My work uses Jest and Enzyme, but for my side project PlayItForward I'll be using Jest and React Testing Library. Luckily Kent C. Dodds has a great course to learn all about Testing JavaScript. Here you'll find my notes and thoughts on the course:
- The most fundamental form of a test is determining if the result is equal to the expected value, if it doesn't match the test should throw an error
ESLint can be used for static testing to help give you confidence in your application without having to set up a bunch of tests. TypeScript can give you a bit of static testing as well to help with type checking and small typos
After mocking you need to clean up to ensure you don't affect the next test that may not want to mock or wants to mock in a different way