Skip to content

Commit e59b0c8

Browse files
Make matchers check type
1 parent 4477bb1 commit e59b0c8

9 files changed

+37
-37
lines changed

Diff for: src/ts-mockito.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,35 @@ export function anyFunction(): any {
8989
return new AnyFunctionMatcher() as any;
9090
}
9191

92-
export function anyNumber(): any {
92+
export function anyNumber(): number {
9393
return new AnyNumberMatcher() as any;
9494
}
9595

96-
export function anyString(): any {
96+
export function anyString(): string {
9797
return new AnyStringMatcher() as any;
9898
}
9999

100100
export function anything(): any {
101101
return new AnythingMatcher() as any;
102102
}
103103

104-
export function between(min: number, max: number): any {
104+
export function between(min: number, max: number): number {
105105
return new BetweenMatcher(min, max) as any;
106106
}
107107

108-
export function deepEqual(expectedValue: any): any {
109-
return new DeepEqualMatcher(expectedValue);
108+
export function deepEqual<T>(expectedValue: T): T {
109+
return new DeepEqualMatcher(expectedValue) as any;
110110
}
111111

112112
export function notNull(): any {
113113
return new NotNullMatcher() as any;
114114
}
115115

116-
export function strictEqual(expectedValue: any): any {
116+
export function strictEqual<T>(expectedValue: T): T {
117117
return new StrictEqualMatcher(expectedValue) as any;
118118
}
119119

120-
export function match(expectedValue: RegExp | string): any {
120+
export function match(expectedValue: RegExp | string): string {
121121
return new MatchingStringMatcher(expectedValue) as any;
122122
}
123123

Diff for: test/MethodAction.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("MethodAction", () => {
1212
const testObj: MethodAction = new MethodAction(methodName, [firstArg, secondArg]);
1313

1414
// when
15-
const result = testObj.isApplicable(methodName, [strictEqual(firstArg), strictEqual(secondArg)]);
15+
const result = testObj.isApplicable(methodName, [strictEqual(firstArg) as any, strictEqual(secondArg) as any]);
1616

1717
// then
1818
expect(result).toBeTruthy();
@@ -28,7 +28,7 @@ describe("MethodAction", () => {
2828
const testObj: MethodAction = new MethodAction(methodName, [firstArg, notMatchingArg]);
2929

3030
// when
31-
const result = testObj.isApplicable(methodName, [strictEqual(firstArg), strictEqual(secondArg)]);
31+
const result = testObj.isApplicable(methodName, [strictEqual(firstArg) as any, strictEqual(secondArg) as any]);
3232

3333
// then
3434
expect(result).toBeFalsy();

Diff for: test/MethodStub.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe("ReturnValueMethodStub", () => {
55
describe("checking if given arg is applicable", () => {
66
it("returns true when arg match", () => {
77
// given
8-
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(10)], 50);
8+
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(10) as any], 50);
99

1010
// when
1111
const result = testObj.isApplicable([10]);
@@ -16,7 +16,7 @@ describe("ReturnValueMethodStub", () => {
1616

1717
it("returns false when arg doesn't match", () => {
1818
// given
19-
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(10)], 50);
19+
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(10) as any], 50);
2020

2121
// when
2222
const result = testObj.isApplicable([999]);
@@ -31,7 +31,7 @@ describe("ReturnValueMethodStub", () => {
3131
// given
3232
const firstValue = 10;
3333
const secondValue = 20;
34-
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue), strictEqual(secondValue)], 50);
34+
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
3535

3636
// when
3737
const result = testObj.isApplicable([firstValue, secondValue]);
@@ -44,7 +44,7 @@ describe("ReturnValueMethodStub", () => {
4444
// given
4545
const firstValue = 10;
4646
const secondValue = 20;
47-
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue), strictEqual(secondValue)], 50);
47+
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
4848

4949
// when
5050
const result = testObj.isApplicable([30, secondValue]);
@@ -57,7 +57,7 @@ describe("ReturnValueMethodStub", () => {
5757
// given
5858
const firstValue = 10;
5959
const secondValue = 20;
60-
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue), strictEqual(secondValue)], 50);
60+
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
6161

6262
// when
6363
const result = testObj.isApplicable([firstValue, 30]);
@@ -70,7 +70,7 @@ describe("ReturnValueMethodStub", () => {
7070
// given
7171
const firstValue = 10;
7272
const secondValue = 20;
73-
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue), strictEqual(secondValue)], 50);
73+
const testObj: ReturnValueMethodStub = new ReturnValueMethodStub(0, [strictEqual(firstValue) as any, strictEqual(secondValue) as any], 50);
7474

7575
// when
7676
const result = testObj.isApplicable([30, 40]);

Diff for: test/matcher/type/AnyNumberMatcher.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe("AnyNumberMatcher", () => {
55
describe("checking if positive number is matching", () => {
66
it("returns true", () => {
77
// given
8-
const testObj: Matcher = anyNumber();
8+
const testObj: Matcher = anyNumber() as any;
99

1010
// when
1111
const result = testObj.match(3);
@@ -18,7 +18,7 @@ describe("AnyNumberMatcher", () => {
1818
describe("checking if negative number is matching", () => {
1919
it("returns true", () => {
2020
// given
21-
const testObj: Matcher = anyNumber();
21+
const testObj: Matcher = anyNumber() as any;
2222

2323
// when
2424
const result = testObj.match(-3);
@@ -31,7 +31,7 @@ describe("AnyNumberMatcher", () => {
3131
describe("checking if zero is matching", () => {
3232
it("returns true", () => {
3333
// given
34-
const testObj: Matcher = anyNumber();
34+
const testObj: Matcher = anyNumber() as any;
3535

3636
// when
3737
const result = testObj.match(0);
@@ -44,7 +44,7 @@ describe("AnyNumberMatcher", () => {
4444
describe("checking if string representation of number is matching", () => {
4545
it("returns false", () => {
4646
// given
47-
const testObj: Matcher = anyNumber();
47+
const testObj: Matcher = anyNumber() as any;
4848

4949
// when
5050
const result = testObj.match("5");
@@ -57,7 +57,7 @@ describe("AnyNumberMatcher", () => {
5757
describe("checking if object is matching", () => {
5858
it("returns false", () => {
5959
// given
60-
const testObj: Matcher = anyNumber();
60+
const testObj: Matcher = anyNumber() as any;
6161

6262
// when
6363
const result = testObj.match({});

Diff for: test/matcher/type/AnyStringMatcher.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe("AnyStringMatcher", () => {
55
describe("checking if number matches", () => {
66
it("returns false", () => {
77
// given
8-
const testObj: Matcher = anyString();
8+
const testObj: Matcher = anyString() as any;
99

1010
// when
1111
const result = testObj.match(3);
@@ -18,7 +18,7 @@ describe("AnyStringMatcher", () => {
1818
describe("checking if object matches", () => {
1919
it("returns false", () => {
2020
// given
21-
const testObj: Matcher = anyString();
21+
const testObj: Matcher = anyString() as any;
2222

2323
// when
2424
const result = testObj.match({});
@@ -31,7 +31,7 @@ describe("AnyStringMatcher", () => {
3131
describe("checking if empty string matches", () => {
3232
it("returns true", () => {
3333
// given
34-
const testObj: Matcher = anyString();
34+
const testObj: Matcher = anyString() as any;
3535

3636
// when
3737
const result = testObj.match("");
@@ -44,7 +44,7 @@ describe("AnyStringMatcher", () => {
4444
describe("checking if sample string matches", () => {
4545
it("returns true", () => {
4646
// given
47-
const testObj: Matcher = anyString();
47+
const testObj: Matcher = anyString() as any;
4848

4949
// when
5050
const result = testObj.match("sampleString");

Diff for: test/matcher/type/BetweenMatcher.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {between} from "../../../src/ts-mockito";
33

44
describe("BetweenMatcher", () => {
55
describe("checking if value matches given min and max", () => {
6-
const testObj: Matcher = between(5, 10);
6+
const testObj: Matcher = between(5, 10) as any;
77

88
describe("when given value is lower than min", () => {
99
it("returns false", () => {
@@ -61,7 +61,7 @@ describe("BetweenMatcher", () => {
6161
// when
6262
let error = null;
6363
try {
64-
const testObj: Matcher = between(10, 9);
64+
const testObj: Matcher = between(10, 9) as any;
6565
} catch (e) {
6666
error = e;
6767
}

Diff for: test/matcher/type/DeepEqualMatcher.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("DeepEqualMatcher", () => {
77
// given
88
const firstValue = 3;
99
const secondValue = 3;
10-
const testObj: Matcher = deepEqual(firstValue);
10+
const testObj: Matcher = deepEqual(firstValue) as any;
1111

1212
// when
1313
const result = testObj.match(secondValue);
@@ -22,7 +22,7 @@ describe("DeepEqualMatcher", () => {
2222
// given
2323
const firstValue = "sampleString";
2424
const secondValue = "sampleString";
25-
const testObj: Matcher = deepEqual(firstValue);
25+
const testObj: Matcher = deepEqual(firstValue) as any;
2626

2727
// when
2828
const result = testObj.match(secondValue);
@@ -37,7 +37,7 @@ describe("DeepEqualMatcher", () => {
3737
// given
3838
const firstValue = {a: 1, b: {c: 2}};
3939
const secondValue = {a: 1, b: {c: 2}};
40-
const testObj: Matcher = deepEqual(firstValue);
40+
const testObj: Matcher = deepEqual(firstValue) as any;
4141

4242
// when
4343
const result = testObj.match(secondValue);
@@ -52,7 +52,7 @@ describe("DeepEqualMatcher", () => {
5252
// given
5353
const firstValue = {a: 1, b: {c: 2}};
5454
const secondValue = {a: 1, b: {c: 99999}};
55-
const testObj: Matcher = deepEqual(firstValue);
55+
const testObj: Matcher = deepEqual(firstValue) as any;
5656

5757
// when
5858
const result = testObj.match(secondValue);
@@ -67,7 +67,7 @@ describe("DeepEqualMatcher", () => {
6767
// given
6868
const firstValue = {a: 1, b: anyString()};
6969
const secondValue = {a: 1, b: "2"};
70-
const testObj: Matcher = deepEqual(firstValue);
70+
const testObj: Matcher = deepEqual(firstValue) as any;
7171

7272
// when
7373
const result = testObj.match(secondValue);
@@ -80,7 +80,7 @@ describe("DeepEqualMatcher", () => {
8080
// given
8181
const firstValue = {a: 1, b: anyString()};
8282
const secondValue = {a: 1, b: 2};
83-
const testObj: Matcher = deepEqual(firstValue);
83+
const testObj: Matcher = deepEqual(firstValue) as any;
8484

8585
// when
8686
const result = testObj.match(secondValue);

Diff for: test/matcher/type/MatchingStringMatcher.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {match} from "../../../src/ts-mockito";
33

44
describe("MatchingStringMatcher", () => {
55
describe("checking if value matches given regexp", () => {
6-
const testObj: Matcher = match(/\w123/);
6+
const testObj: Matcher = match(/\w123/) as any;
77

88
describe("when given value matches regexp", () => {
99
it("returns true", () => {

Diff for: test/matcher/type/StrictEqualMatcher.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe("StrictEqualMatcher", () => {
55
describe("checking if string representation of number matches with number", () => {
66
it("returns false", () => {
77
// given
8-
const testObj: Matcher = strictEqual("5");
8+
const testObj: Matcher = strictEqual("5") as any;
99

1010
// when
1111
const result = testObj.match(5);
@@ -18,7 +18,7 @@ describe("StrictEqualMatcher", () => {
1818
describe("checking if false matches with zero", () => {
1919
it("returns false", () => {
2020
// given
21-
const testObj: Matcher = strictEqual(false);
21+
const testObj: Matcher = strictEqual(false) as any;
2222

2323
// when
2424
const result = testObj.match(0);
@@ -31,7 +31,7 @@ describe("StrictEqualMatcher", () => {
3131
describe("checking if true matches with one", () => {
3232
it("returns false", () => {
3333
// given
34-
const testObj: Matcher = strictEqual(true);
34+
const testObj: Matcher = strictEqual(true) as any;
3535

3636
// when
3737
const result = testObj.match(1);
@@ -44,7 +44,7 @@ describe("StrictEqualMatcher", () => {
4444
describe("checking if same strings matches", () => {
4545
it("returns true", () => {
4646
// given
47-
const testObj: Matcher = strictEqual("5");
47+
const testObj: Matcher = strictEqual("5") as any;
4848

4949
// when
5050
const result = testObj.match("5");

0 commit comments

Comments
 (0)