forked from NagRock/ts-mockito
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlog-invocations.spec.ts
43 lines (33 loc) · 1.08 KB
/
log-invocations.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { anything, imock, instance, resetStubs, spy, verify, when } from "../src/ts-mockito";
interface Foo {
getBar(): string;
getBarWithArg(arg: string): string;
}
describe('log-invocations', () => {
let c: Console;
beforeEach(() => {
c = spy(console);
});
afterEach(() => {
resetStubs(c);
});
it("should log invocations of a method", () => {
const foo: Foo = imock({logInvocations: true});
instance(foo).getBar();
verify(foo.getBar()).once();
verify(c.log("call: getBar()")).once();
});
it("should log invocations of a method having behaviors", () => {
const foo: Foo = imock({logInvocations: true});
when(foo.getBar()).thenReturn("bar");
instance(foo).getBar();
verify(foo.getBar()).once();
verify(c.log("call: getBar()")).once();
});
it("should log invocations of a method with arguments", () => {
const foo: Foo = imock({logInvocations: true});
instance(foo).getBarWithArg("hello world");
verify(foo.getBarWithArg(anything())).once();
verify(c.log("call: getBarWithArg(\"hello world\")")).once();
});
});