|
| 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", t => { |
| 14 | + const calculator = Substitute.for<Calculator>(); |
| 15 | + |
| 16 | + // Do not mock and do not call |
| 17 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 18 | + calculator.didNotReceive().add(1, Arg.any()); |
| 19 | + calculator.didNotReceive().add(1, 2); |
| 20 | + |
| 21 | + t.pass(); |
| 22 | +}); |
| 23 | + |
| 24 | +test("check didNotReceive after not mocking but calling a method", t => { |
| 25 | + const calculator = Substitute.for<Calculator>(); |
| 26 | + |
| 27 | + // Do not mock, but call |
| 28 | + calculator.add(1, 2); |
| 29 | + |
| 30 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 31 | + calculator.didNotReceive().add(1, Arg.any()); |
| 32 | + calculator.didNotReceive().add(1, 2); |
| 33 | + |
| 34 | + t.pass(); |
| 35 | +}); |
| 36 | + |
| 37 | +test("check didNotReceive after mocking but not calling a method", t => { |
| 38 | + const calculator = Substitute.for<Calculator>(); |
| 39 | + |
| 40 | + // Mock but do not call |
| 41 | + calculator.add(1, 2).returns(3); |
| 42 | + |
| 43 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 44 | + calculator.didNotReceive().add(1, Arg.any()); |
| 45 | + calculator.didNotReceive().add(1, 2); |
| 46 | + |
| 47 | + t.pass(); |
| 48 | +}); |
| 49 | + |
| 50 | +test("check didNotReceive after mocking and calling a method", t => { |
| 51 | + const calculator = Substitute.for<Calculator>(); |
| 52 | + |
| 53 | + // Mock and call |
| 54 | + calculator.add(1, 2).returns(3); |
| 55 | + calculator.add(1, 2); |
| 56 | + |
| 57 | + calculator.didNotReceive().add(Arg.any(), Arg.any()); |
| 58 | + calculator.didNotReceive().add(1, Arg.any()); |
| 59 | + calculator.didNotReceive().add(1, 2); |
| 60 | + |
| 61 | + t.pass(); |
| 62 | +}); |
0 commit comments