-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learn React with TypeScript
By :

In this section, we will start by understanding the fundamental parts of a Vitest 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 they have 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.
Vitest looks for tests in files with particular extensions. These file extensions are .test.ts
for tests on pure functions and .test.tsx
for tests on components. Alternatively, a...