prostub 1.0.0 → 1.1.0
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/LICENSE.txt +7 -0
- package/README.md +14 -0
- package/index.d.ts +10 -0
- package/index.js +11 -0
- package/package.json +8 -3
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2025 Haringat
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# ProStub
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
A mocking/stubbing library for JavaScript, inspired by Mockito. It is evironment-agnostic, `@types/node` is included as a dev-dependency to provide `console` during testing. The production code at run-time only relies on the JavaScript standard library
|
|
6
|
+
|
|
7
|
+
## Building
|
|
8
|
+
|
|
9
|
+
The library is automatically built when running `pnpm install`, but it can be re-built manually by running `npm run prepare`.
|
|
10
|
+
|
|
11
|
+
## Testing
|
|
12
|
+
|
|
13
|
+
Right now there are no unit tests. However, there is a `test.ts`, which examplifies how the library is meant to be used. It can be executed by running `npm test`.
|
|
14
|
+
|
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]: {
|
|
@@ -172,6 +179,8 @@ declare class InvocationVerification<const TArgs extends Array<unknown>, TReturn
|
|
|
172
179
|
wasAfter(otherInvocation: InvocationVerification<TArgs, TReturn>): void;
|
|
173
180
|
returned(validator: (result: TReturn) => boolean): void;
|
|
174
181
|
threw(validator: (error: unknown) => boolean): void;
|
|
182
|
+
didNotThrow(): void;
|
|
183
|
+
hadArguments(...validators: ArgumentPredicate<TArgs>): void;
|
|
175
184
|
}
|
|
176
185
|
|
|
177
186
|
declare class FunctionVerification<const TArgs extends Array<unknown>, TReturn> {
|
|
@@ -199,3 +208,4 @@ declare function verify<const TObject extends object>(mockOrSpy: TObject & {
|
|
|
199
208
|
}): Verifiable<TObject>;
|
|
200
209
|
|
|
201
210
|
export { answer, callThrough, defaultValue, delegateTo, fixedValue, mock, noop, returnFixed, returnSerial, spy, stub, throwOnCall, trackValue, verify, when };
|
|
211
|
+
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,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostub",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
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
|
+
},
|
|
10
|
+
"author": "Haringat",
|
|
5
11
|
"license": "MIT",
|
|
6
12
|
"peerDependencies": {
|
|
7
13
|
"tslib": "^2.8.1"
|
|
8
14
|
},
|
|
9
|
-
"
|
|
10
|
-
"main": "index.mjs",
|
|
15
|
+
"main": "index.js",
|
|
11
16
|
"types": "index.d.ts",
|
|
12
17
|
"scripts": {
|
|
13
18
|
"test": "echo \"If you read this, all tests succeeded in the pipeline. Refer to the source-code repository to verify.\""
|