Let's create our first unit test in our project to test the required function in Form.tsx:
- Start by creating a file called Form.test.tsx in the src folder. We'll use this file for our test code, to test the code in Form.tsx.
The test.tsx extension is important because Jest automatically looks for files with this extension when finding tests to execute. Note that if our tests don't contain any JSX, we could use a test.ts extension.
- Let's import the function we want to test, along with a TypeScript type we need for a parameter value:
import { required, IValues } from "./Form";
- Let's start to create our test using the Jest test function:
test("When required is called with empty title, 'This must be ...