[SOLVED] How to pass an undefined value to jest.expect?


I’m coding on a TS project with strictNullChecks.
I want to make sure that the result of a function is undefined:

const company = await getRepository(Company).findOne({ id: deletedID });

However, ESLint gives me this warning on the expect line: Passing nullable argument to function that expects non nullable.

I could also do expect(company === undefined).toBe(true) but is there a way to use .toBeUndefined()?


You can use as like this:

expect(company as any).toBeUndefined();

Answered By – Sebastian Kaczmarek

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *