Skip to content

Commit

Permalink
Allow to verify a mock method call never occurred in Strict mode.
Browse files Browse the repository at this point in the history
When in strict mode verifying that a method call never occured was
adding an expected call without passing the expected times. The default
times being once, when verifyAll is called on the mock the tests failed
with Configured setups expected once but was never invoked.
  • Loading branch information
Alexandru Codreanu committed Nov 9, 2017
1 parent b7ca662 commit bf38de8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/StaticMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class StaticMock<T> extends MockBase<T> {

verify<TResult>(expression: all.IFunc2<T, TResult>, times: all.Times): void {
const call = MethodCall.ofStaticMock(this, expression);
call.verifiable(times);
this._interceptor.addExpectedCall(call);
try {
this._interceptor.verifyCallCount(call, times);
Expand Down
8 changes: 8 additions & 0 deletions test/spec/Mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ describe("Mock", () => {
expect(() => mock.object.doNumber(999)).to.throw(Error);
});

it("should support verify never when behavior is strict", () => {

const mock = Mock.ofType(TypeMoqTests.Doer, MockBehavior.Strict);

mock.verify(m => m.doVoid(), Times.never());
mock.verifyAll();
});

describe("dynamic mock", () => {

it("should return default value when no setup found and behavior is loose", () => {
Expand Down

0 comments on commit bf38de8

Please sign in to comment.