|
| 1 | +import test from "ava"; |
| 2 | + |
| 3 | +import { Substitute, Arg } from "../../src/index"; |
| 4 | + |
| 5 | +interface Calculator { |
| 6 | + add(a: number, b: number): number; |
| 7 | + subtract(a: number, b: number): number; |
| 8 | + divide(a: number, b: number): number; |
| 9 | + |
| 10 | + isEnabled: boolean; |
| 11 | +} |
| 12 | + |
| 13 | +test("check didNotReceive after not mocking and not calling a method", () => { |
| 14 | + const calculator = Substitute.for<Calculator>(); |
| 15 | + |
| 16 | + // Do not mock and do not call |
| 17 | + calculator.didNotReceive().add(1, 2); |
| 18 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 19 | + calculator.didNotReceive().add(1, Arg.any()); |
| 20 | +}); |
| 21 | + |
| 22 | +test("check didNotReceive after not mocking but calling a method", () => { |
| 23 | + const calculator = Substitute.for<Calculator>(); |
| 24 | + |
| 25 | + // Do not mock, but call |
| 26 | + calculator.add(1, 2); |
| 27 | + calculator.didNotReceive().add(1, 2); |
| 28 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 29 | + calculator.didNotReceive().add(1, Arg.any()); |
| 30 | +}); |
| 31 | + |
| 32 | +test("check didNotReceive after mocking but not calling a method", () => { |
| 33 | + const calculator = Substitute.for<Calculator>(); |
| 34 | + |
| 35 | + // Mock but do not call |
| 36 | + calculator.add(1, 2).returns(3); |
| 37 | + calculator.didNotReceive().add(1, 2); |
| 38 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 39 | + calculator.didNotReceive().add(1, Arg.any()); |
| 40 | +}); |
| 41 | + |
| 42 | +test("check didNotReceive after mocking and calling a method", () => { |
| 43 | + const calculator = Substitute.for<Calculator>(); |
| 44 | + |
| 45 | + // Mock and call |
| 46 | + calculator.add(1, 2).returns(3); |
| 47 | + calculator.add(1, 2); |
| 48 | + calculator.didNotReceive().add(1, 2); |
| 49 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 50 | + calculator.didNotReceive().add(1, Arg.any()); |
| 51 | +}); |
0 commit comments