Testing pure functions
In this section, we will start by understanding the fundamental parts of a Jest test. Then, we will put this into practice by implementing tests on a pure function in the checklist component.
A pure function has a consistent output value for a given set of parameter values. These functions depend only on the function parameters and nothing outside the function, and also don’t change any argument values passed into them. So, pure functions are nice for learning how to write tests because there are no tricky side effects to deal with.
In this section, we will also cover how to test exceptions, which is useful for testing type assertion functions. Finally, at the end of this section, we will learn how to run the tests in a test suite.
Understanding a Jest test
Jest is preinstalled in a Create React App project and configured to look for tests in files with particular extensions. These file extensions are .test.ts
for tests on pure functions...