nestjs icon indicating copy to clipboard operation
nestjs copied to clipboard

ts-jest - When function is called with a mock, toHaveBeenCalledWith() always succeed even when it should not

Open maxime-dupuis opened this issue 1 year ago • 5 comments

it('mock called with another mock', async () => {
  class Cheese {
    constructor(public name: string) {}
  }
  class Potato {
    private cheese: Cheese;
    public applyCheese(cheese: Cheese) {
      this.cheese = cheese;
    }
  }
  const mockPotato = createMock<Potato>();
  const mockCheese = createMock<Cheese>();

  mockPotato.applyCheese(mockCheese);

  expect(mockPotato.applyCheese).toHaveBeenCalledTimes(1);
  // These all pass, but they should fail because applyCheese wasn't called with these values
  expect(mockPotato.applyCheese).toHaveBeenCalledWith('kaboom');
  expect(mockPotato.applyCheese).toHaveBeenCalledWith(42);
  expect(mockPotato.applyCheese).toHaveBeenCalledWith(null);
  // This one should pass (and does)
  expect(mockPotato.applyCheese).toHaveBeenCalledWith(mockCheese);
});

maxime-dupuis avatar Feb 27 '24 14:02 maxime-dupuis

Experiencing the same issue. Is there something we can do about it?

VonRehberg avatar Jun 27 '24 08:06 VonRehberg

Hey @underfisk , any plans on when the package will be updated? The issue is fixed with the merge request #752 Thanks in advance!

VonRehberg avatar Aug 09 '24 12:08 VonRehberg

Hey @underfisk , any plans on when the package will be updated?

The issue is fixed with the merge request #752

Thanks in advance!

Only @WonderPanda can publish

underfisk avatar Aug 09 '24 16:08 underfisk

Just published. This should be available in @golevelup/[email protected]

WonderPanda avatar Aug 09 '24 17:08 WonderPanda

Thanks a lot man!

VonRehberg avatar Aug 09 '24 20:08 VonRehberg