prostub 1.0.1 → 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.
Files changed (3) hide show
  1. package/index.d.ts +10 -0
  2. package/index.js +11 -0
  3. 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]: {
@@ -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,17 @@
1
1
  {
2
2
  "name": "prostub",
3
- "version": "1.0.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
+ },
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": {