prostub 1.0.1 → 1.1.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/index.d.ts +12 -14
- package/index.js +11 -0
- package/package.json +6 -2
package/index.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ type Stubbable<T extends object> = {
|
|
|
49
49
|
-readonly [K in keyof T]: Stub<T, K>;
|
|
50
50
|
};
|
|
51
51
|
type Stub<TThis extends object, TKey extends keyof TThis> = TThis[TKey] extends (...args: infer TArgs) => infer TReturn ? FunctionStub<TThis, TKey, TArgs, TReturn> : PropertyStub<TThis, TKey>;
|
|
52
|
+
type Mock<T extends Object> = T & {
|
|
53
|
+
[mock$1]: {
|
|
54
|
+
stubs: {
|
|
55
|
+
-readonly [TKey in keyof T]?: Stub<T, TKey>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
52
59
|
|
|
53
60
|
declare function mock<const TObject extends object>(clazz: Type<TObject>): TObject & {
|
|
54
61
|
[mock$1]: {
|
|
@@ -72,13 +79,7 @@ declare function spy<const TObject extends object>(realObject: TObject): TObject
|
|
|
72
79
|
};
|
|
73
80
|
};
|
|
74
81
|
|
|
75
|
-
declare function stub<const TObject extends object>(mockOrSpy: TObject
|
|
76
|
-
[mock$1]: {
|
|
77
|
-
stubs: {
|
|
78
|
-
-readonly [TKey in keyof TObject]?: Stub<TObject, TKey>;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
}): Stubbable<TObject>;
|
|
82
|
+
declare function stub<const TObject extends object>(mockOrSpy: Mock<TObject>): Stubbable<TObject>;
|
|
82
83
|
|
|
83
84
|
declare function answer<const TObject extends object, const TKey extends keyof TObject, const TArgs extends Array<unknown>, const TReturn>(answerFunction: (this: TObject, ...args: TArgs) => TReturn): FunctionStub<TObject, TKey, TArgs, TReturn>;
|
|
84
85
|
|
|
@@ -172,6 +173,8 @@ declare class InvocationVerification<const TArgs extends Array<unknown>, TReturn
|
|
|
172
173
|
wasAfter(otherInvocation: InvocationVerification<TArgs, TReturn>): void;
|
|
173
174
|
returned(validator: (result: TReturn) => boolean): void;
|
|
174
175
|
threw(validator: (error: unknown) => boolean): void;
|
|
176
|
+
didNotThrow(): void;
|
|
177
|
+
hadArguments(...validators: ArgumentPredicate<TArgs>): void;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
declare class FunctionVerification<const TArgs extends Array<unknown>, TReturn> {
|
|
@@ -190,12 +193,7 @@ type Verifiable<T> = {
|
|
|
190
193
|
readonly [TKey in keyof T]: T[TKey] extends (...args: infer TArgs) => infer TReturn ? FunctionVerification<TArgs, TReturn> : PropertyVerification<T[TKey]>;
|
|
191
194
|
};
|
|
192
195
|
|
|
193
|
-
declare function verify<const TObject extends object>(mockOrSpy: TObject
|
|
194
|
-
[mock$1]: {
|
|
195
|
-
stubs: {
|
|
196
|
-
-readonly [TKey in keyof TObject]?: Stub<TObject, TKey>;
|
|
197
|
-
};
|
|
198
|
-
};
|
|
199
|
-
}): Verifiable<TObject>;
|
|
196
|
+
declare function verify<const TObject extends object>(mockOrSpy: Mock<TObject>): Verifiable<TObject>;
|
|
200
197
|
|
|
201
198
|
export { answer, callThrough, defaultValue, delegateTo, fixedValue, mock, noop, returnFixed, returnSerial, spy, stub, throwOnCall, trackValue, verify, when };
|
|
199
|
+
export type { Mock };
|
package/index.js
CHANGED
|
@@ -509,6 +509,17 @@ class InvocationVerification {
|
|
|
509
509
|
throw new Error(`The thrown exception did not satisfy the provided validator.`);
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
|
+
didNotThrow() {
|
|
513
|
+
if (this.#call.exception) {
|
|
514
|
+
throw new Error(`Expected invocation to not throw an exception, but it threw: ${this.#call.exception}`);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
hadArguments(...validators) {
|
|
518
|
+
const hasArguments = validators.every((validator, index) => validator(this.#call.args[index]));
|
|
519
|
+
if (!hasArguments) {
|
|
520
|
+
throw new Error(`The invocation arguments did not satisfy the provided validators.`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
512
523
|
}
|
|
513
524
|
|
|
514
525
|
class FunctionVerification {
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostub",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A TypeScript library for creating mocks.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/haringat/prostub.git"
|
|
9
|
+
},
|
|
5
10
|
"author": "Haringat",
|
|
6
11
|
"license": "MIT",
|
|
7
12
|
"peerDependencies": {
|
|
8
13
|
"tslib": "^2.8.1"
|
|
9
14
|
},
|
|
10
|
-
"type": "module",
|
|
11
15
|
"main": "index.js",
|
|
12
16
|
"types": "index.d.ts",
|
|
13
17
|
"scripts": {
|