Checking for null and undefined
Explore how to use Jest matchers to test for null and undefined values in your React app functions. Understand how to apply toBeNull, toBeUndefined, and their negations to verify both expected and unexpected results, enhancing your test coverage and reliability.
We'll cover the following...
We'll cover the following...
Checking for null
The project for this lesson contains two functions, getPerson and getCompany, that are being tested. A copy of the project’s code is in the code widget below:
import { getCompany } from "./data";
test("Should return correct company object when found", async () => {
const company = await getCompany(1);
expect(company.name).toBe("Dibbert Group");
});Starter project
At the moment, only the happy path is being tested. The cases when the person or company is not found are not covered at the moment.
Let’s focus on the unhappy path test for getPerson. In data.getPerson.test.js, Implement this test using a ...