Skip to content

Commit

Permalink
Add tests for didNotReceive (#75)
Browse files Browse the repository at this point in the history
* Add tests for didNotReceive #72

* Add t.pass()

* Swap didNotReceived calls
  • Loading branch information
Evgeny Shevchenko authored and ffMathy committed Dec 7, 2019
1 parent 5545b5b commit 59bd915
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions spec/issues/72.test.ts
Original file line number Diff line number Diff line change
@@ -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<Calculator>();

// 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<Calculator>();

// 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<Calculator>();

// 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<Calculator>();

// 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();
});

0 comments on commit 59bd915

Please sign in to comment.