From 59bd9156fa58ecf616db2ffa4f5877e140b118ce Mon Sep 17 00:00:00 2001 From: Evgeny Shevchenko Date: Sat, 7 Dec 2019 14:29:15 +0300 Subject: [PATCH] Add tests for didNotReceive (#75) * Add tests for didNotReceive #72 * Add t.pass() * Swap didNotReceived calls --- spec/issues/72.test.ts | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 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..ec04b68 --- /dev/null +++ b/spec/issues/72.test.ts @@ -0,0 +1,62 @@ +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", t => { + const calculator = Substitute.for(); + + // Do not mock and do not call + calculator.didNotReceive().add(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); + + t.pass(); +}); + +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(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); + + t.pass(); +}); + +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(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); + + t.pass(); +}); + +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(Arg.any(), Arg.any()); + calculator.didNotReceive().add(1, Arg.any()); + calculator.didNotReceive().add(1, 2); + + t.pass(); +});