Table of Contents
Intro to Testing
IntroductionKent C. Dodds introduces the course as a primer for testing and testing frameworks so that students gain confidence in testing, and the ability to write tests that are maintainable. Ken also covers cloning the git repository and sets the routine for the course.
Automated TestingKent introduces some common bugs, what is generally done about these bugs, and gives an introduction to tests, with examples on what static, unit, integration, and a look of E2E tests.
Your First Test SolutionAfter walking through the solution to the Your First Test Exercise, Kent provides instructions for the next exercise, which is about writing a simple assertion library.
Jest Testing FrameworkKent provides an overview of Jest's assertion methods.
Course Code WalkthroughKent reviews Jest and demonstrates watch mode on files in the repository. - (review - approach to tech issue)
Unit Test DemoKent demonstrates how to write a pure function with Jest and introduces test-driven development.
Writing a Basic Unit Test SolutionKent walks through the userToJson exercise in multiple ways and teaches how to use your test code to communicate intent.
Test Factories & Colocating Tests Q&AKent fields a question that segues into test factories, describe blocks, colocating tests, Jest globals, other tools to use in addition to Jest, and other topics.
Code CoverageAfter introducing code coverage reports, which are a way to see what code is covered by your tests, Kent reviews its benefits as well as addressing the pitfalls of misinterpreting the data or misusing the feature.
Monkey Patch a Mock ExerciseAfter explaining mocking, Kent introduces the exercise where the goal is to create a mock for a dependency in a test. The simplest form of mocking a function in a module is by using monkey patching to swap the actual implementation with a fake implementation.
Monkey Path a Mock SolutionKent codes the solution to the previous exercise by monkey patching a fake implementation of the getWinner function so that a more specific assertion can be made.
Asserting Calling a Mock ExerciseIn this exercise, students are to gain more confidence out of a mock by asserting that it is being called in the way that is expected.
Asserting Calling a Mock SolutionAfter coding the solution for the mock function to keep track of how it is called and to add an assertion for it, Kent introduces the next exercise with the goal of implementing jest.spyOn. - (review - approach to tech issue)
Using Jest spyOnKent codes the solution to Jest spyOn, which allows the user to keep track of when existing functions are called and mock their implementations.
Using Jest MockKent codes the solution using jest.mock, which allows the user to mock an entire module to avoid monkey patching module exports. Then Kent demonstrates another exercise that allows the user to apply the mock in almost all of the tests, rather than having it isolated.
Jest Q&AWhile answering a student question about the appropriateness to mock an API when the actual API is still in development, Kent is lead to the topic of discussing whether to use dependency injection or mocking.
Using a __mocks__ directoryKent walks through a test from scratch that tests the user's module. Then Kent shows the importance of being explicit in tests and discusses edge cases for this implementation. - this was highlighted in red
More Mocking with UsersKent reviews an example of how to construct a test that ensures the users being retrieved from a database are what is expected.
Unit Tests for Express MiddlewareTo test Express middleware that interacts with the database, Kent shows that one can either mock or initialize the database. In this demonstration, Kent initializes the database and asserts that the endpoints are returning the correct items from the database.
Unit Tests for Express Middleware SolutionKent live codes the solution to the Unit Tests for Express Middleware exercise, where the test checks that all posts are returning from the database, the specific post is being returned, and updatePost updates the correct post with the given changes.
Test Object FactoriesAfter demonstrating how object factories are constructed, using a previous example as scaffolding, Kent gives reviews test-cleanup.
Test-Driven DevelopmentKent begins the section by introducing an exercise with the instructions to implement a delete function using test driven development (TDD). He then goes into further detail by outlining of the process of TDD, and in what use cases that it's a good idea to implement the practice.
Test-Driven Development SolutionThe solution to the exercise introduced at the beginning of Test Driven Development is live-coded.
Basic Integration Test for a Node ServerKent codes an integration test for a node server noting differences when testing on the server, such as the need to stop the server after the tests are completed. Then Kent introduces a tool to help write these tests called Axios, a promise based HTTP client.