Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maxime-dupuis opened this issue Feb 27, 2024 · 1 comment
Labels

Comments

@maxime-dupuis
Copy link

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);
});
@VonRehberg
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants