ts-jest - When function is called with a mock, toHaveBeenCalledWith() always succeed even when it should not
maxime-dupuis opened this issue · 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);
});
Experiencing the same issue. Is there something we can do about it?