From fc0b8ca9d755de9da17c7d52f79337214b51b449 Mon Sep 17 00:00:00 2001 From: Eugene Shevchenko Date: Fri, 6 Dec 2019 22:10:54 +0300 Subject: [PATCH 1/3] Add tests for didNotReceive #72 --- spec/issues/72.test.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/issues/72.test.ts diff --git a/spec/issues/72.test.ts b/spec/issues/72.test.ts new file mode 100644 index 0000000..1aa4646 --- /dev/null +++ b/spec/issues/72.test.ts @@ -0,0 +1,51 @@ +import test from "ava"; + +import { Substitute, Arg } from "../../src/index"; + +interface Calculator { + add(a: number, b: number): number; + subtract(a: number, b: number): number; + divide(a: number, b: number): number; + + isEnabled: boolean; +} + +test("check didNotReceive after not mocking and not calling a method", () => { + const calculator = Substitute.for(); + + // Do not mock and do not call + calculator.didNotReceive().add(1, 2); + calculator.didNotReceive().add(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); +}); + +test("check didNotReceive after not mocking but calling a method", () => { + const calculator = Substitute.for(); + + // Do not mock, but call + calculator.add(1, 2); + calculator.didNotReceive().add(1, 2); + calculator.didNotReceive().add(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); +}); + +test("check didNotReceive after mocking but not calling a method", () => { + const calculator = Substitute.for(); + + // Mock but do not call + calculator.add(1, 2).returns(3); + calculator.didNotReceive().add(1, 2); + calculator.didNotReceive().add(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); +}); + +test("check didNotReceive after mocking and calling a method", () => { + const calculator = Substitute.for(); + + // Mock and call + calculator.add(1, 2).returns(3); + calculator.add(1, 2); + calculator.didNotReceive().add(1, 2); + calculator.didNotReceive().add(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); +}); From f4aeb15349311780e6406e398df4f6e517381f99 Mon Sep 17 00:00:00 2001 From: Eugene Shevchenko Date: Sat, 7 Dec 2019 14:09:07 +0300 Subject: [PATCH 2/3] Add t.pass() --- spec/issues/72.test.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/spec/issues/72.test.ts b/spec/issues/72.test.ts index 1aa4646..9a9b95e 100644 --- a/spec/issues/72.test.ts +++ b/spec/issues/72.test.ts @@ -10,42 +10,53 @@ interface Calculator { isEnabled: boolean; } -test("check didNotReceive after not mocking and not calling a method", () => { +test("check didNotReceive after not mocking and not calling a method", t => { const calculator = Substitute.for(); // Do not mock and do not call calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + + t.pass(); }); -test("check didNotReceive after not mocking but calling a method", () => { +test("check didNotReceive after not mocking but calling a method", t => { const calculator = Substitute.for(); // Do not mock, but call calculator.add(1, 2); + calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + + t.pass(); }); -test("check didNotReceive after mocking but not calling a method", () => { +test("check didNotReceive after mocking but not calling a method", t => { const calculator = Substitute.for(); // Mock but do not call calculator.add(1, 2).returns(3); + calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + + t.pass(); }); -test("check didNotReceive after mocking and calling a method", () => { +test("check didNotReceive after mocking and calling a method", t => { const calculator = Substitute.for(); // Mock and call calculator.add(1, 2).returns(3); calculator.add(1, 2); + calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + + t.pass(); }); From 460e5a89d244fcb682f078a01dd21acbf74cc327 Mon Sep 17 00:00:00 2001 From: Eugene Shevchenko Date: Sat, 7 Dec 2019 14:24:21 +0300 Subject: [PATCH 3/3] Swap didNotReceived calls --- spec/issues/72.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/issues/72.test.ts b/spec/issues/72.test.ts index 9a9b95e..ec04b68 100644 --- a/spec/issues/72.test.ts +++ b/spec/issues/72.test.ts @@ -14,9 +14,9 @@ test("check didNotReceive after not mocking and not calling a method", t => { const calculator = Substitute.for(); // Do not mock and do not call - calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); t.pass(); }); @@ -27,9 +27,9 @@ test("check didNotReceive after not mocking but calling a method", t => { // Do not mock, but call calculator.add(1, 2); - calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); t.pass(); }); @@ -40,9 +40,9 @@ test("check didNotReceive after mocking but not calling a method", t => { // Mock but do not call calculator.add(1, 2).returns(3); - calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); t.pass(); }); @@ -54,9 +54,9 @@ test("check didNotReceive after mocking and calling a method", t => { calculator.add(1, 2).returns(3); calculator.add(1, 2); - calculator.didNotReceive().add(1, 2); calculator.didNotReceive().add(Arg.any(), Arg.any()); calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); t.pass(); });