From the course: Testing in React with Vitest

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

First unit test

First unit test

- [Instructor] Welcome. In this lesson, we'll work on all what we've been discussing, write our first unit test, and run it with Vitest. Now it's not uncommon to see testing get all the hits, but I assure you testing is worth all the hype. Here, we have our starting code for the lesson from all what we've been working on. You can see we have a test folder, and inside, we have a file called setupTests.ts. In this file, we have the configurations for our testing environment before each test suit runs. We import just matches to assist us in testing dome elements, which we'll see more of as we progress. In our source folder, let's create a file called math.ts. In this file, we'll create two functions, the first one called sum, and the second one called multiply. Let's do this by exporting two functions called sum, which I know takes a number and b, a number, and returns a number. Let's do that and copy the same for multiply. Sum takes two values, a and b, of type number and returns the…

Contents