forked from NagRock/ts-mockito
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMethodStub.spec.ts
96 lines (75 loc) · 3.18 KB
/
MethodStub.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {ReturnValueMethodStub} from "../src/stub/ReturnValueMethodStub";
import {strictEqual} from "../src/ts-mockito";
describe("ReturnValueMethodStub", () => {
describe("checking if given arg is applicable", () => {
it("returns true when arg match", () => {
// given
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(10) as any], 50);
// when
const result = testObj.isApplicable([10]);
// then
expect(result).toBeTruthy();
});
it("returns false when arg doesn't match", () => {
// given
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(10) as any], 50);
// when
const result = testObj.isApplicable([999]);
// then
expect(result).toBeFalsy();
});
});
describe("checking if more than one arg is applicable", () => {
it("returns true when all matches", () => {
// given
const firstValue = 10;
const secondValue = 20;
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
// when
const result = testObj.isApplicable([firstValue, secondValue]);
// then
expect(result).toBeTruthy();
});
it("returns false when first arg doesn't match", () => {
// given
const firstValue = 10;
const secondValue = 20;
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
// when
const result = testObj.isApplicable([30, secondValue]);
// then
expect(result).toBeFalsy();
});
it("returns false when second arg doesn't match", () => {
// given
const firstValue = 10;
const secondValue = 20;
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
// when
const result = testObj.isApplicable([firstValue, 30]);
// then
expect(result).toBeFalsy();
});
it("returns false when both args doesn't match", () => {
// given
const firstValue = 10;
const secondValue = 20;
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
// when
const result = testObj.isApplicable([30, 40]);
// then
expect(result).toBeFalsy();
});
});
describe("getting mocked value", () => {
it("returns it", () => {
// given
const mockedValue = 50;
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [], mockedValue);
// when
const result = testObj.getValue();
// then
expect(result).toEqual(mockedValue);
});
});
});