strong-mock 8.0.0-beta.0 → 8.0.0-beta.2

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.
@@ -1,6 +1,7 @@
1
- import { PendingExpectation } from '../when/pending-expectation';
2
- import { InvocationCount } from './invocation-count';
3
- declare type PromiseStub<R, P> = {
1
+ import type { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
+ import type { PendingExpectation } from '../when/pending-expectation';
3
+ import type { InvocationCount } from './invocation-count';
4
+ export declare type PromiseStub<R, P> = {
4
5
  /**
5
6
  * Set the return value for the current call.
6
7
  *
@@ -41,7 +42,7 @@ declare type PromiseStub<R, P> = {
41
42
  */
42
43
  thenReject(): InvocationCount;
43
44
  };
44
- declare type NonPromiseStub<R> = {
45
+ export declare type NonPromiseStub<R> = {
45
46
  /**
46
47
  * Set the return value for the current call.
47
48
  *
@@ -68,6 +69,9 @@ declare type NonPromiseStub<R> = {
68
69
  */
69
70
  thenThrow(): InvocationCount;
70
71
  };
71
- export declare type Stub<T> = [T] extends [Promise<infer U>] ? PromiseStub<U, T> : NonPromiseStub<T>;
72
- export declare const createReturns: <R>(pendingExpectation: PendingExpectation) => Stub<R>;
73
- export {};
72
+ export declare const createReturns: (pendingExpectation: PendingExpectation, repository: ExpectationRepository) => {
73
+ thenReturn: (returnValue: any) => InvocationCount;
74
+ thenThrow: (errorOrMessage?: Error | string) => InvocationCount;
75
+ thenResolve: (promiseValue: any) => InvocationCount;
76
+ thenReject: (errorOrMessage?: Error | string) => InvocationCount;
77
+ };
@@ -1,4 +1,4 @@
1
- import { Mock } from '../mock/mock';
1
+ import type { Mock } from '../mock/mock';
2
2
  /**
3
3
  * Remove any remaining expectations on the given mock.
4
4
  *
@@ -1,5 +1,5 @@
1
- import { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import { Mock } from '../mock/mock';
1
+ import type { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
+ import type { Mock } from '../mock/mock';
3
3
  export declare const verifyRepo: (repository: ExpectationRepository) => void;
4
4
  /**
5
5
  * Verify that all expectations on the given mock have been met.
@@ -1,28 +1,31 @@
1
- import { Expectation, ReturnValue } from '../expectation/expectation';
2
- import { ExpectationRepository } from '../expectation/repository/expectation-repository';
3
- import { Property } from '../proxy';
4
- export declare type ExpectationFactory = (property: Property, args: any[] | undefined, returnValue: ReturnValue) => Expectation;
1
+ import type { Expectation } from '../expectation/expectation';
2
+ import type { ReturnValue } from '../expectation/repository/return-value';
3
+ import type { ConcreteMatcher } from '../mock/options';
4
+ import type { Property } from '../proxy';
5
+ /**
6
+ * An expectation has to be built incrementally, starting first with the property
7
+ * being accessed inside {@link createStub}, then any arguments passed to it, and ending
8
+ * it with the returned value from {@link createReturns}.
9
+ */
5
10
  export interface PendingExpectation {
6
- start(repo: ExpectationRepository): void;
11
+ setProperty(prop: Property): void;
12
+ setArgs(args: any[] | undefined): void;
7
13
  finish(returnValue: ReturnValue): Expectation;
8
- clear(): void;
9
- property: Property;
10
- args: any[] | undefined;
11
14
  /**
12
15
  * Used by `pretty-format`.
13
16
  */
14
17
  toJSON(): string;
15
18
  }
16
- export declare class RepoSideEffectPendingExpectation implements PendingExpectation {
19
+ export declare type ExpectationFactory = (property: Property, args: any[] | undefined, returnValue: ReturnValue, concreteMatcher: ConcreteMatcher, exactParams: boolean) => Expectation;
20
+ export declare class PendingExpectationWithFactory implements PendingExpectation {
17
21
  private createExpectation;
18
- private _repo;
19
- private _args;
20
- private _property;
21
- constructor(createExpectation: ExpectationFactory);
22
- start(repo: ExpectationRepository): void;
23
- set property(value: Property);
24
- set args(value: any[] | undefined);
22
+ private concreteMatcher;
23
+ private exactParams;
24
+ private args;
25
+ private property;
26
+ constructor(createExpectation: ExpectationFactory, concreteMatcher: ConcreteMatcher, exactParams: boolean);
27
+ setProperty(value: Property): void;
28
+ setArgs(value: any[] | undefined): void;
25
29
  finish(returnValue: ReturnValue): Expectation;
26
- clear(): void;
27
30
  toJSON(): string;
28
31
  }
@@ -1,4 +1,8 @@
1
- import { Stub } from '../return/returns';
1
+ import type { NonPromiseStub, PromiseStub } from '../return/returns';
2
+ interface When {
3
+ <R>(expectation: () => Promise<R>): PromiseStub<R, Promise<R>>;
4
+ <R>(expectation: () => R): NonPromiseStub<R>;
5
+ }
2
6
  /**
3
7
  * Set an expectation on a mock.
4
8
  *
@@ -24,4 +28,5 @@ import { Stub } from '../return/returns';
24
28
  * const fn = mock<(x: number) => Promise<number>();
25
29
  * when(() => fn(23)).thenResolve(42);
26
30
  */
27
- export declare const when: <R>(expectation: () => R) => Stub<R>;
31
+ export declare const when: When;
32
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strong-mock",
3
- "version": "8.0.0-beta.0",
3
+ "version": "8.0.0-beta.2",
4
4
  "description": "Simple type safe mocking library",
5
5
  "keywords": [
6
6
  "tdd",
@@ -21,25 +21,25 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "jest-matcher-utils": "~27.5.0",
24
+ "jest-matcher-utils": "~28.1.0",
25
25
  "lodash": "~4.17.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@nighttrax/eslint-config-ts": "~10.0.0-beta.2",
29
- "@tdd-buffet/jest-config": "~4.1.0",
29
+ "@tdd-buffet/jest-config": "~5.0.0",
30
30
  "@tdd-buffet/tsconfig": "~1.0.0",
31
- "@types/jest": "~27.5.0",
31
+ "@types/jest": "~28.1.6",
32
32
  "@types/node": "~17.0.8",
33
33
  "@types/lodash": "~4.14.0",
34
34
  "doctoc": "~2.2.0",
35
- "eslint": "~8.19.0",
36
- "jest": "~27.5.0",
35
+ "eslint": "~8.24.0",
36
+ "jest": "~28.1.3",
37
37
  "microbundle": "~0.15.0",
38
38
  "standard-version": "~9.5.0",
39
39
  "strip-ansi": "~6.0.0",
40
40
  "strong-mock": "~6.0.0",
41
41
  "tslib": "~2.4.0",
42
- "typescript": "~4.7.0"
42
+ "typescript": "~4.8.0"
43
43
  },
44
44
  "scripts": {
45
45
  "docs": "doctoc --title '**Table of Contents**' README.md",
@@ -1,41 +0,0 @@
1
- import { Property } from '../../proxy';
2
- import { Expectation, ReturnValue } from '../expectation';
3
- import { CallMap, ExpectationRepository } from './expectation-repository';
4
- export declare type CountableExpectation = {
5
- expectation: Expectation;
6
- matchCount: number;
7
- };
8
- export declare abstract class BaseRepository implements ExpectationRepository {
9
- protected readonly expectations: Map<Property, CountableExpectation[]>;
10
- private readonly expectedCallStats;
11
- private readonly unexpectedCallStats;
12
- add(expectation: Expectation): void;
13
- clear(): void;
14
- get(property: Property): ReturnValue;
15
- getAllProperties(): Property[];
16
- getCallStats(): {
17
- expected: CallMap;
18
- unexpected: CallMap;
19
- };
20
- getUnmet(): Expectation[];
21
- /**
22
- * We got a method call that doesn't match any expectation,
23
- * what should we return?
24
- */
25
- protected abstract getValueForUnexpectedCall(property: Property, args: any[]): any;
26
- /**
27
- * We got a property access that doesn't match any expectation,
28
- * what should we return?
29
- */
30
- protected abstract getValueForUnexpectedAccess(property: Property): ReturnValue;
31
- protected abstract consumeExpectation(expectation: CountableExpectation): void;
32
- /**
33
- * Record an expected property access/method call.
34
- */
35
- private recordExpected;
36
- /**
37
- * Record an unexpected property access/method call.
38
- */
39
- private recordUnexpected;
40
- private countAndConsume;
41
- }
@@ -1,10 +0,0 @@
1
- import { BaseRepository, CountableExpectation } from './base-repository';
2
- import { Property } from '../../proxy';
3
- /**
4
- * Throw if no expectation matches.
5
- */
6
- export declare class StrongRepository extends BaseRepository {
7
- protected consumeExpectation(expectation: CountableExpectation): void;
8
- protected getValueForUnexpectedCall(property: Property, args: any[]): never;
9
- protected getValueForUnexpectedAccess(property: Property): never;
10
- }
@@ -1,17 +0,0 @@
1
- import { BaseRepository, CountableExpectation } from './base-repository';
2
- import { Expectation } from '../expectation';
3
- import { ExpectationRepository } from './expectation-repository';
4
- /**
5
- * Always return something, even if no expectations match.
6
- *
7
- * WARNING: this is in development, do not use
8
- */
9
- export declare class WeakRepository extends BaseRepository implements ExpectationRepository {
10
- private repeating;
11
- protected getValueForUnexpectedCall: () => null;
12
- protected getValueForUnexpectedAccess: () => {
13
- value: () => null;
14
- };
15
- protected consumeExpectation(expectation: CountableExpectation): void;
16
- add(expectation: Expectation): void;
17
- }