-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for didNotReceive #72 * Add t.pass() * Swap didNotReceived calls
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |