forked from NagRock/ts-mockito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocking.properties.spec.ts
67 lines (51 loc) · 1.97 KB
/
mocking.properties.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {MethodToStub} from "../src/MethodToStub";
import {instance, mock, verify, when} from "../src/ts-mockito";
describe("mocking", () => {
let mockedFoo: FooWithProperties;
let foo: FooWithProperties;
if (typeof Proxy === "undefined") {
pending("Testing browser doesn't support Proxy.");
}
describe("mocking object with properties (that don't have getters)", () => {
it("does create own property descriptors on mock after when is called", () => {
// given
// when
mockedFoo = mock(FooWithProperties);
when(mockedFoo.sampleNumber).thenReturn(42);
// then
expect((mockedFoo.sampleNumber as any) instanceof MethodToStub).toBe(true);
});
it("does create own property descriptors on instance", () => {
// given
mockedFoo = mock(FooWithProperties);
foo = instance(mockedFoo);
// when
when(mockedFoo.sampleNumber).thenReturn(42);
// then
expect(foo.sampleNumber).toBe(42);
});
it("works with verification if property is stubbed", () => {
// given
mockedFoo = mock(FooWithProperties);
foo = instance(mockedFoo);
when(mockedFoo.sampleNumber).thenReturn(42);
// when
const value = foo.sampleNumber;
// then
expect(() => verify(mockedFoo.sampleNumber).once()).not.toThrow();
});
it("works with verification if property is unstubbed", () => {
// given
mockedFoo = mock(FooWithProperties);
foo = instance(mockedFoo);
(when(mockedFoo.sampleNumber) as any).thenDoNothing();
// when
const value = foo.sampleNumber;
// then
expect(() => verify(mockedFoo.sampleNumber).once()).not.toThrow();
});
});
});
class FooWithProperties {
public readonly sampleNumber: number;
}