.toBeUndefined()

Use .toBeUndefined to check that a variable is undefined. For example, if you want to check that a function bestDrinkForFlavor(flavor) returns undefined for the 'octopus' flavor, because there is no good octopus-flavored drink:

  1. test('the best drink for octopus flavor is undefined', () => {
  2. expect(bestDrinkForFlavor('octopus')).toBeUndefined();
  3. });

You could write expect(bestDrinkForFlavor('octopus')).toBe(undefined), but it's better practice to avoid referring to undefined directly in your code.