tsmockit 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Mock/Any.d.ts +4 -0
- package/Mock/Any.js +4 -0
- package/Mock/Mock.d.ts +27 -0
- package/Mock/Mock.js +27 -0
- package/package.json +1 -1
package/Mock/Any.d.ts
CHANGED
package/Mock/Any.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Any = exports.ANY_VALUE = void 0;
|
|
4
4
|
exports.ANY_VALUE = 'ANYTHING';
|
|
5
|
+
/**
|
|
6
|
+
* Returns a value Mock understands to represent "ANYTHING" casted to "T"
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
5
9
|
function Any() {
|
|
6
10
|
return exports.ANY_VALUE;
|
|
7
11
|
}
|
package/Mock/Mock.d.ts
CHANGED
|
@@ -2,11 +2,38 @@ import { Times } from './Times';
|
|
|
2
2
|
export declare class Mock<T> {
|
|
3
3
|
private memberSignatureMaps;
|
|
4
4
|
private object;
|
|
5
|
+
/**
|
|
6
|
+
* The mock object of the given type "T" to inject as a substitute to a concrete implementation
|
|
7
|
+
*/
|
|
5
8
|
get Object(): T;
|
|
9
|
+
/**
|
|
10
|
+
* Configure what the mock object will return when a given member is accessed
|
|
11
|
+
* @param member
|
|
12
|
+
* @param returns
|
|
13
|
+
*/
|
|
6
14
|
Setup(member: (func: T) => any, returns?: any): void;
|
|
15
|
+
/**
|
|
16
|
+
* Configure a setup that will only resolve on the first time the member is registered
|
|
17
|
+
* @param member
|
|
18
|
+
* @param returns
|
|
19
|
+
*/
|
|
7
20
|
SetupOnce(member: (func: T) => any, returns?: any): void;
|
|
21
|
+
/**
|
|
22
|
+
* Configure a set of setups that will only resolve on the first time the member is registered
|
|
23
|
+
* @param setups
|
|
24
|
+
*/
|
|
8
25
|
SetupSequence(setups: [(func: T) => any, any][]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Return the number of times a given member was referenced
|
|
28
|
+
* @param member
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
9
31
|
TimesMemberCalled(member: (func: T) => any): number;
|
|
32
|
+
/**
|
|
33
|
+
* Make an assertion that a given member was referenced a given number of times
|
|
34
|
+
* @param member
|
|
35
|
+
* @param times
|
|
36
|
+
*/
|
|
10
37
|
Verify(member: (func: T) => any, times: Times | number): void;
|
|
11
38
|
private setup;
|
|
12
39
|
private getReturnValueForProperty;
|
package/Mock/Mock.js
CHANGED
|
@@ -9,32 +9,59 @@ var Mock = /** @class */ (function () {
|
|
|
9
9
|
this.object = {};
|
|
10
10
|
}
|
|
11
11
|
Object.defineProperty(Mock.prototype, "Object", {
|
|
12
|
+
/**
|
|
13
|
+
* The mock object of the given type "T" to inject as a substitute to a concrete implementation
|
|
14
|
+
*/
|
|
12
15
|
get: function () {
|
|
13
16
|
return this.object;
|
|
14
17
|
},
|
|
15
18
|
enumerable: false,
|
|
16
19
|
configurable: true
|
|
17
20
|
});
|
|
21
|
+
/**
|
|
22
|
+
* Configure what the mock object will return when a given member is accessed
|
|
23
|
+
* @param member
|
|
24
|
+
* @param returns
|
|
25
|
+
*/
|
|
18
26
|
Mock.prototype.Setup = function (member, returns) {
|
|
19
27
|
if (returns === void 0) { returns = null; }
|
|
20
28
|
this.setup(member, returns);
|
|
21
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Configure a setup that will only resolve on the first time the member is registered
|
|
32
|
+
* @param member
|
|
33
|
+
* @param returns
|
|
34
|
+
*/
|
|
22
35
|
Mock.prototype.SetupOnce = function (member, returns) {
|
|
23
36
|
if (returns === void 0) { returns = null; }
|
|
24
37
|
this.setup(member, returns, true);
|
|
25
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Configure a set of setups that will only resolve on the first time the member is registered
|
|
41
|
+
* @param setups
|
|
42
|
+
*/
|
|
26
43
|
Mock.prototype.SetupSequence = function (setups) {
|
|
27
44
|
var _this = this;
|
|
28
45
|
setups.forEach(function (setup) {
|
|
29
46
|
_this.SetupOnce(setup[0], setup[1]);
|
|
30
47
|
});
|
|
31
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Return the number of times a given member was referenced
|
|
51
|
+
* @param member
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
32
54
|
Mock.prototype.TimesMemberCalled = function (member) {
|
|
33
55
|
var _a;
|
|
34
56
|
var memberSignatureMap = SignatureService_1.SignatureService.GetMemberSignatureMap(member);
|
|
35
57
|
var functionMap = this.getFunctionMapsFromSignature(memberSignatureMap, (_a = memberSignatureMap.functionMaps[0]) === null || _a === void 0 ? void 0 : _a.state).functionMapForArgs;
|
|
36
58
|
return (functionMap === null || functionMap === void 0 ? void 0 : functionMap.timesCalled) || 0;
|
|
37
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Make an assertion that a given member was referenced a given number of times
|
|
62
|
+
* @param member
|
|
63
|
+
* @param times
|
|
64
|
+
*/
|
|
38
65
|
Mock.prototype.Verify = function (member, times) {
|
|
39
66
|
var timesCalled = this.TimesMemberCalled(member);
|
|
40
67
|
var signature = SignatureService_1.SignatureService.GetMemberSignatureMap(member).signature;
|