.toHaveReturnedWith(value)

Also under the alias: .toReturnWith(value)

Use .toHaveReturnedWith to ensure that a mock function returned a specific value.

For example, let's say you have a mock drink that returns the name of the beverage that was consumed. You can write:

  1. test('drink returns La Croix', () => {
  2. const beverage = {name: 'La Croix'};
  3. const drink = jest.fn(beverage => beverage.name);
  4. drink(beverage);
  5. expect(drink).toHaveReturnedWith('La Croix');
  6. });