strong-mock 9.0.1 → 9.2.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 (42) hide show
  1. package/README.md +41 -25
  2. package/dist/index.cjs +1191 -0
  3. package/dist/index.d.cts +584 -0
  4. package/dist/index.d.ts +584 -14
  5. package/dist/index.js +658 -842
  6. package/package.json +35 -21
  7. package/dist/errors/api.d.ts +0 -13
  8. package/dist/errors/diff.d.ts +0 -4
  9. package/dist/errors/unexpected-access.d.ts +0 -5
  10. package/dist/errors/unexpected-call.d.ts +0 -14
  11. package/dist/errors/verify.d.ts +0 -8
  12. package/dist/expectation/expectation.d.ts +0 -27
  13. package/dist/expectation/repository/expectation-repository.d.ts +0 -90
  14. package/dist/expectation/repository/flexible-repository.d.ts +0 -38
  15. package/dist/expectation/repository/return-value.d.ts +0 -13
  16. package/dist/expectation/strong-expectation.d.ts +0 -30
  17. package/dist/index.js.map +0 -1
  18. package/dist/matchers/contains-object.d.ts +0 -28
  19. package/dist/matchers/deep-equals.d.ts +0 -16
  20. package/dist/matchers/is-any.d.ts +0 -11
  21. package/dist/matchers/is-array.d.ts +0 -22
  22. package/dist/matchers/is-number.d.ts +0 -12
  23. package/dist/matchers/is-plain-object.d.ts +0 -17
  24. package/dist/matchers/is-string.d.ts +0 -15
  25. package/dist/matchers/is.d.ts +0 -9
  26. package/dist/matchers/it.d.ts +0 -10
  27. package/dist/matchers/matcher.d.ts +0 -93
  28. package/dist/matchers/will-capture.d.ts +0 -21
  29. package/dist/mock/defaults.d.ts +0 -11
  30. package/dist/mock/map.d.ts +0 -16
  31. package/dist/mock/mock.d.ts +0 -24
  32. package/dist/mock/mode.d.ts +0 -6
  33. package/dist/mock/options.d.ts +0 -99
  34. package/dist/mock/stub.d.ts +0 -5
  35. package/dist/print.d.ts +0 -10
  36. package/dist/proxy.d.ts +0 -48
  37. package/dist/return/invocation-count.d.ts +0 -44
  38. package/dist/return/returns.d.ts +0 -61
  39. package/dist/verify/reset.d.ts +0 -20
  40. package/dist/verify/verify.d.ts +0 -27
  41. package/dist/when/expectation-builder.d.ts +0 -26
  42. package/dist/when/when.d.ts +0 -32
@@ -1,16 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Compare values using deep equality.
4
- *
5
- * @param expected
6
- * @param strict By default, this matcher will treat a missing key in an object
7
- * and a key with the value `undefined` as not equal. It will also consider
8
- * non `Object` instances with different constructors as not equal. Setting
9
- * this to `false` will consider the objects in both cases as equal.
10
- *
11
- * @see {@link It.containsObject} or {@link It.isArray} if you want to nest matchers.
12
- * @see {@link It.is} if you want to use strict equality.
13
- */
14
- export declare const deepEquals: <T>(expected: T, { strict, }?: {
15
- strict?: boolean;
16
- }) => TypeMatcher<T>;
@@ -1,11 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Match any value, including `undefined` and `null`.
4
- *
5
- * @example
6
- * const fn = mock<(x: number, y: string) => number>();
7
- * when(() => fn(It.isAny(), It.isAny())).thenReturn(1);
8
- *
9
- * fn(23, 'foobar') === 1
10
- */
11
- export declare const isAny: () => TypeMatcher<any>;
@@ -1,22 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Match an array.
4
- *
5
- * Supports nested matchers.
6
- *
7
- * @param containing If given, the matched array has to contain ALL of these
8
- * elements in ANY order.
9
- *
10
- * @example
11
- * const fn = mock<(arr: number[]) => number>();
12
- * when(() => fn(It.isArray())).thenReturn(1);
13
- * when(() => fn(It.isArray([2, 3]))).thenReturn(2);
14
- *
15
- * fn({ length: 1, 0: 42 }) // throws
16
- * fn([]) === 1
17
- * fn([3, 2, 1]) === 2
18
- *
19
- * @example
20
- * It.isArray([It.isString({ containing: 'foobar' })])
21
- */
22
- export declare const isArray: <T extends unknown[]>(containing?: T) => TypeMatcher<T>;
@@ -1,12 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Match any number.
4
- *
5
- * @example
6
- * const fn = mock<(x: number) => number>();
7
- * when(() => fn(It.isNumber())).returns(42);
8
- *
9
- * fn(20.5) === 42
10
- * fn(NaN) // throws
11
- */
12
- export declare const isNumber: () => TypeMatcher<number>;
@@ -1,17 +0,0 @@
1
- import type { Property } from '../proxy';
2
- import type { TypeMatcher } from './matcher';
3
- type ObjectType = Record<Property, unknown>;
4
- /**
5
- * Matches any plain object e.g. object literals or objects created with `Object.create()`.
6
- *
7
- * Classes, arrays, maps, sets etc. are not considered plain objects.
8
- * You can use {@link containsObject} or {@link matches} to match those.
9
- *
10
- * @example
11
- * const fn = mock<({ foo: string }) => number>();
12
- * when(() => fn(It.isPlainObject())).thenReturn(42);
13
- *
14
- * fn({ foo: 'bar' }) // returns 42
15
- */
16
- export declare const isPlainObject: <T extends ObjectType>() => TypeMatcher<T>;
17
- export {};
@@ -1,15 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Match any string.
4
- *
5
- * @param matching An optional string or RegExp to match the string against.
6
- * If it's a string, a case-sensitive search will be performed.
7
- *
8
- * @example
9
- * const fn = mock<(x: string, y: string) => number>();
10
- * when(() => fn(It.isString(), It.isString('bar'))).returns(42);
11
- *
12
- * fn('foo', 'baz') // throws
13
- * fn('foo', 'bar') === 42
14
- */
15
- export declare const isString: (matching?: string | RegExp) => TypeMatcher<string>;
@@ -1,9 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Compare values using `Object.is`.
4
- *
5
- * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
6
- *
7
- * @see It.deepEquals A matcher that uses deep equality.
8
- */
9
- export declare const is: <T = unknown>(expected: T) => TypeMatcher<T>;
@@ -1,10 +0,0 @@
1
- export { deepEquals } from './deep-equals';
2
- export { is } from './is';
3
- export { isAny } from './is-any';
4
- export { isArray } from './is-array';
5
- export { isNumber } from './is-number';
6
- export { isPlainObject } from './is-plain-object';
7
- export { containsObject } from './contains-object';
8
- export { isString } from './is-string';
9
- export { matches } from './matcher';
10
- export { willCapture } from './will-capture';
@@ -1,93 +0,0 @@
1
- export declare const MATCHER_SYMBOL: unique symbol;
2
- export type MatcherDiffer = (actual: any) => {
3
- actual: any;
4
- expected: any;
5
- };
6
- export type MatcherOptions = {
7
- /**
8
- * Will be called when printing the diff between an expectation and the
9
- * (mismatching) received arguments.
10
- *
11
- * With this function you can pretty print the `actual` and `expected` values
12
- * according to your matcher's logic.
13
- *
14
- * @param actual The actual value received by this matcher, same as the one
15
- * in `matches`.
16
- *
17
- * @example
18
- * const neverMatcher = It.matches(() => false, {
19
- * getDiff: (actual) => ({ actual, expected: 'never' })
20
- * });
21
- *
22
- * when(() => fn(neverMatcher)).thenReturn(42);
23
- *
24
- * fn(42);
25
- * // - Expected
26
- * // + Received
27
- * //
28
- * // - 'never'
29
- * // + 42
30
- */
31
- getDiff: MatcherDiffer;
32
- /**
33
- * Will be called when printing arguments for an unexpected or unmet expectation.
34
- *
35
- * @example
36
- * const neverMatcher = It.matches(() => false, {
37
- * toString: () => 'never'
38
- * });
39
- * when(() => fn(neverMatcher)).thenReturn(42);
40
- *
41
- * fn(42);
42
- * // Unmet expectations:
43
- * // when(() => fn(never)).thenReturn(42)
44
- */
45
- toString: () => string;
46
- };
47
- /**
48
- * You MUST use {@link It.matches} to create this branded type.
49
- */
50
- export interface Matcher extends MatcherOptions {
51
- [MATCHER_SYMBOL]: boolean;
52
- /**
53
- * Will be called with the received value and should return whether it matches
54
- * the expectation.
55
- */
56
- matches: (actual: any) => boolean;
57
- }
58
- /**
59
- * This takes the shape of T to satisfy call sites, but strong-mock will only
60
- * care about the matcher type.
61
- */
62
- export type TypeMatcher<T> = T & Matcher;
63
- /**
64
- * Used to test if an expectation is an argument is a custom matcher.
65
- */
66
- export declare function isMatcher(f: unknown): f is Matcher;
67
- export declare const getMatcherDiffs: (matchers: Matcher[], args: unknown[]) => {
68
- actual: unknown[];
69
- expected: unknown[];
70
- };
71
- /**
72
- * Create a custom matcher.
73
- *
74
- * @param predicate Will receive the actual value and return whether it matches the expectation.
75
- * @param options
76
- * @param options.toString An optional function that should return a string that will be
77
- * used when the matcher needs to be printed in an error message. By default,
78
- * it stringifies `predicate`.
79
- * @param options.getDiff An optional function that will be called when printing the
80
- * diff for a failed expectation. It will only be called if there's a mismatch
81
- * between the expected and received values i.e. `predicate(actual)` fails.
82
- * By default, the `toString` method will be used to format the expected value,
83
- * while the received value will be returned as-is.
84
- *
85
- * @example
86
- * // Create a matcher for positive numbers.
87
- * const fn = mock<(x: number) => number>();
88
- * when(() => fn(It.matches(x => x >= 0))).thenReturn(42);
89
- *
90
- * fn(2) === 42
91
- * fn(-1) // throws
92
- */
93
- export declare const matches: <T>(predicate: (actual: T) => boolean, options?: Partial<MatcherOptions>) => TypeMatcher<T>;
@@ -1,21 +0,0 @@
1
- import type { TypeMatcher } from './matcher';
2
- /**
3
- * Matches anything and stores the received value.
4
- *
5
- * This should not be needed for most cases, but can be useful if you need
6
- * access to a complex argument outside the expectation e.g. to test a
7
- * callback.
8
- *
9
- * @param name If given, this name will be printed in error messages.
10
- *
11
- * @example
12
- * const fn = mock<(cb: (value: number) => number) => void>();
13
- * const matcher = It.willCapture();
14
- * when(() => fn(matcher)).thenReturn();
15
- *
16
- * fn(x => x + 1);
17
- * matcher.value?.(3) === 4
18
- */
19
- export declare const willCapture: <T = unknown>(name?: string) => TypeMatcher<T> & {
20
- value: T | undefined;
21
- };
@@ -1,11 +0,0 @@
1
- import type { MockOptions } from './options';
2
- export type StrongMockDefaults = Required<MockOptions>;
3
- export declare let currentDefaults: StrongMockDefaults;
4
- /**
5
- * Override strong-mock's defaults.
6
- *
7
- * @param newDefaults These will be applied to the library defaults. Multiple
8
- * calls don't stack e.g. calling this with `{}` will clear any previously
9
- * applied defaults.
10
- */
11
- export declare const setDefaults: (newDefaults: MockOptions) => void;
@@ -1,16 +0,0 @@
1
- import type { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import type { ExpectationBuilder } from '../when/expectation-builder';
3
- import type { StrongMockDefaults } from './defaults';
4
- import type { Mock } from './mock';
5
- export declare const setActiveMock: (mock: Mock<any>) => void;
6
- export declare const clearActiveMock: () => void;
7
- export declare const getActiveMock: () => Mock<any>;
8
- type MockState = {
9
- repository: ExpectationRepository;
10
- builder: ExpectationBuilder;
11
- options: StrongMockDefaults;
12
- };
13
- export declare const getMockState: (mock: Mock<any>) => MockState;
14
- export declare const setMockState: (mock: Mock<any>, state: MockState) => void;
15
- export declare const getAllMocks: () => [Mock<any>, MockState][];
16
- export {};
@@ -1,24 +0,0 @@
1
- import type { MockOptions } from './options';
2
- export type Mock<T> = T;
3
- /**
4
- * Create a type safe mock.
5
- *
6
- * @see {@link when} Set expectations on the mock using `when`.
7
- *
8
- * @param options Configure the options for this specific mock, overriding any
9
- * defaults that were set with {@link setDefaults}.
10
- * @param options.unexpectedProperty Controls what happens when an unexpected
11
- * property is accessed.
12
- * @param options.concreteMatcher The matcher that will be used when one isn't
13
- * specified explicitly.
14
- * @param options.exactParams Controls whether the number of received arguments
15
- * has to match the expectation.
16
- *
17
- * @example
18
- * const fn = mock<() => number>();
19
- *
20
- * when(() => fn()).thenReturn(23);
21
- *
22
- * fn() === 23;
23
- */
24
- export declare const mock: <T>({ unexpectedProperty, concreteMatcher, exactParams, }?: MockOptions) => Mock<T>;
@@ -1,6 +0,0 @@
1
- export declare enum Mode {
2
- EXPECT = 0,
3
- CALL = 1
4
- }
5
- export declare const setMode: (mode: Mode) => void;
6
- export declare const getMode: () => Mode;
@@ -1,99 +0,0 @@
1
- import type { Matcher } from '../matchers/matcher';
2
- export type ConcreteMatcher = <T>(expected: T) => Matcher;
3
- export declare enum UnexpectedProperty {
4
- /**
5
- * Throw an error immediately.
6
- *
7
- * @example
8
- * // Will throw "Didn't expect foo to be accessed".
9
- * const { foo } = service;
10
- *
11
- * // Will throw "Didn't expect foo to be accessed",
12
- * // without printing the arguments.
13
- * foo(42);
14
- */
15
- THROW = 0,
16
- /**
17
- * Return a function that will throw if called. This can be useful if your
18
- * code destructures a function but never calls it.
19
- *
20
- * It will also improve error messages for unexpected calls because arguments
21
- * will be captured instead of throwing immediately on the property access.
22
- *
23
- * The function will be returned even if the property is not supposed to be a
24
- * function. This could cause weird behavior at runtime, when your code expects
25
- * e.g. a number and gets a function instead.
26
- *
27
- * @example
28
- * // This will NOT throw.
29
- * const { foo } = service;
30
- *
31
- * // This will NOT throw, and might produce unexpected results.
32
- * foo > 0
33
- *
34
- * // Will throw "Didn't expect foo(42) to be called".
35
- * foo(42);
36
- */
37
- CALL_THROW = 1
38
- }
39
- export interface MockOptions {
40
- /**
41
- * Controls what should be returned for a property with no expectations.
42
- *
43
- * A property with no expectations is a property that has no `when`
44
- * expectations set on it. It can also be a property that ran out of `when`
45
- * expectations.
46
- *
47
- * The default is to return a function that will throw when called.
48
- *
49
- * @example
50
- * const foo = mock<{ bar: () => number }>();
51
- * foo.bar() // unexpected property access
52
- *
53
- * @example
54
- * const foo = mock<{ bar: () => number }>();
55
- * when(() => foo.bar()).thenReturn(42);
56
- * foo.bar() === 42
57
- * foo.bar() // unexpected property access
58
- */
59
- unexpectedProperty?: UnexpectedProperty;
60
- /**
61
- * If `true`, the number of received arguments in a function/method call has to
62
- * match the number of arguments set in the expectation.
63
- *
64
- * If `false`, extra parameters are considered optional and checked by the
65
- * TypeScript compiler instead.
66
- *
67
- * You may want to set this to `true` if you're not using TypeScript,
68
- * or if you want to be extra strict.
69
- *
70
- * @example
71
- * const fn = mock<(value?: number) => number>({ exactParams: true });
72
- * when(() => fn()).thenReturn(42);
73
- *
74
- * fn(100) // throws with exactParams, returns 42 without
75
- */
76
- exactParams?: boolean;
77
- /**
78
- * The matcher that will be used when one isn't specified explicitly.
79
- *
80
- * The most common use case is replacing the default {@link It.deepEquals}
81
- * matcher with {@link It.is}, but you can also use {@link It.matches} to
82
- * create a custom matcher.
83
- *
84
- * @param expected The concrete expected value received from the
85
- * {@link when} expectation.
86
- *
87
- * @example
88
- * const fn = mock<(value: number[]) => boolean>({
89
- * concreteMatcher: It.is
90
- * });
91
- *
92
- * const expected = [1, 2, 3];
93
- * when(() => fn(expected).thenReturn(true);
94
- *
95
- * fn([1, 2, 3]); // throws because different array instance
96
- * fn(expected); // OK
97
- */
98
- concreteMatcher?: ConcreteMatcher;
99
- }
@@ -1,5 +0,0 @@
1
- import type { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import type { ExpectationBuilder } from '../when/expectation-builder';
3
- import type { Mock } from './mock';
4
- import { Mode } from './mode';
5
- export declare const createStub: <T>(repo: ExpectationRepository, builder: ExpectationBuilder, getCurrentMode: () => Mode) => Mock<T>;
package/dist/print.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { Expectation } from './expectation/expectation';
2
- import type { ReturnValue } from './expectation/repository/return-value';
3
- import type { Property } from './proxy';
4
- export declare const printProperty: (property: Property) => string;
5
- export declare const printValue: (arg: unknown) => string;
6
- export declare const printCall: (property: Property, args?: any[]) => string;
7
- export declare const printReturns: ({ isError, isPromise, value }: ReturnValue, min: number, max: number) => string;
8
- export declare const printWhen: (property: Property, args: any[] | undefined) => string;
9
- export declare const printExpectation: (property: Property, args: any[] | undefined, returnValue: ReturnValue, min: number, max: number) => string;
10
- export declare const printRemainingExpectations: (expectations: Expectation[]) => string;
package/dist/proxy.d.ts DELETED
@@ -1,48 +0,0 @@
1
- import type { Mock } from './mock/mock';
2
- export type Property = string | symbol;
3
- export interface ProxyTraps {
4
- /**
5
- * Called when accessing any property on an object, except for
6
- * `.call`, `.apply` and `.bind`.
7
- */
8
- property: (property: Property) => unknown;
9
- /**
10
- * Called when calling a function.
11
- *
12
- * @example
13
- * ```
14
- * fn(...args)
15
- * ```
16
- *
17
- * @example
18
- * ```
19
- * fn.call(this, ...args)
20
- * ```
21
- *
22
- * @example
23
- * ```
24
- * fn.apply(this, [...args])
25
- * ```
26
- *
27
- * @example
28
- * ```
29
- * Reflect.apply(fn, this, [...args])
30
- * ```
31
- */
32
- apply: (args: unknown[]) => unknown;
33
- /**
34
- * Called when getting the proxy's own enumerable keys.
35
- *
36
- * @example
37
- * ```
38
- * Object.keys(proxy);
39
- * ```
40
- *
41
- * @example
42
- * ```
43
- * const foo = { ...proxy };
44
- * ```
45
- */
46
- ownKeys: () => Property[];
47
- }
48
- export declare const createProxy: <T>(traps: ProxyTraps) => Mock<T>;
@@ -1,44 +0,0 @@
1
- import type { Expectation } from '../expectation/expectation';
2
- export interface InvocationCount {
3
- /**
4
- * Expect a call to be made at least `min` times and at most `max` times.
5
- */
6
- between: (min: number, max: number) => void;
7
- /**
8
- * Expect a call to be made exactly `exact` times.
9
- *
10
- * Shortcut for `between(exact, exact)`.
11
- */
12
- times: (exact: number) => void;
13
- /**
14
- * Expect a call to be made any number of times, including never.
15
- *
16
- * Shortcut for `between(0, Infinity)`.
17
- */
18
- anyTimes: () => void;
19
- /**
20
- * Expect a call to be made at least `min` times.
21
- *
22
- * Shortcut for `between(min, Infinity)`.
23
- */
24
- atLeast: (min: number) => void;
25
- /**
26
- * Expect a call to be made at most `max` times.
27
- *
28
- * Shortcut for `between(0, max)`.
29
- */
30
- atMost: (max: number) => void;
31
- /**
32
- * Expect a call to be made exactly once.
33
- *
34
- * Shortcut for `times(1)`.
35
- */
36
- once: () => void;
37
- /**
38
- * Expect a call to be made exactly twice.
39
- *
40
- * Shortcut for `times(2)`.
41
- */
42
- twice: () => void;
43
- }
44
- export declare const createInvocationCount: (expectation: Expectation) => InvocationCount;
@@ -1,61 +0,0 @@
1
- import type { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import type { ExpectationBuilder } from '../when/expectation-builder';
3
- import type { InvocationCount } from './invocation-count';
4
- export type PromiseStub<R, P> = {
5
- /**
6
- * Set the return value for the current call.
7
- *
8
- * @param value This needs to be of the same type as the value returned
9
- * by the call inside `when`.
10
- *
11
- * @example
12
- * when(() => fn()).thenReturn(Promise.resolve(23));
13
- *
14
- * @example
15
- * when(() => fn()).thenReturn(Promise.reject({ foo: 'bar' });
16
- */
17
- thenReturn: (value: P) => InvocationCount;
18
- /**
19
- * Set the return value for the current call.
20
- *
21
- * @param promiseValue This needs to be of the same type as the value inside
22
- * the promise returned by the `when` callback.
23
- *
24
- * @example
25
- * when(() => fn()).thenResolve('foo');
26
- */
27
- thenResolve: (promiseValue: R) => InvocationCount;
28
- /**
29
- * Make the current call reject with the given error.
30
- *
31
- * @param error An `Error` instance. You can pass just a message, and
32
- * it will be wrapped in an `Error` instance. If you want to reject with
33
- * a non error then use the {@link thenReturn} method.
34
- *
35
- * @example
36
- * when(() => fn()).thenReject(new Error('oops'));
37
- */
38
- thenReject: ((error: Error) => InvocationCount) & ((message: string) => InvocationCount) & (() => InvocationCount);
39
- };
40
- export type NonPromiseStub<R> = {
41
- /**
42
- * Set the return value for the current call.
43
- *
44
- * @param returnValue This needs to be of the same type as the value returned
45
- * by the `when` callback.
46
- */
47
- thenReturn: (returnValue: R) => InvocationCount;
48
- /**
49
- * Make the current call throw the given error.
50
- *
51
- * @param error The error instance. If you want to throw a simple `Error`
52
- * you can pass just the message.
53
- */
54
- thenThrow: ((error: Error) => InvocationCount) & ((message: string) => InvocationCount) & (() => InvocationCount);
55
- };
56
- export declare const createReturns: (builder: ExpectationBuilder, repository: ExpectationRepository) => {
57
- thenReturn: (returnValue: any) => InvocationCount;
58
- thenThrow: (errorOrMessage?: Error | string) => InvocationCount;
59
- thenResolve: (promiseValue: any) => InvocationCount;
60
- thenReject: (errorOrMessage?: Error | string) => InvocationCount;
61
- };
@@ -1,20 +0,0 @@
1
- import type { Mock } from '../mock/mock';
2
- /**
3
- * Remove any remaining expectations on the given mock.
4
- *
5
- * @example
6
- * const fn = mock<() => number>();
7
- *
8
- * when(() => fn()).thenReturn(23);
9
- *
10
- * reset(fn);
11
- *
12
- * fn(); // throws
13
- */
14
- export declare const reset: (mock: Mock<any>) => void;
15
- /**
16
- * Reset all existing mocks.
17
- *
18
- * @see reset
19
- */
20
- export declare const resetAll: () => void;
@@ -1,27 +0,0 @@
1
- import type { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import type { Mock } from '../mock/mock';
3
- export declare const verifyRepo: (repository: ExpectationRepository) => void;
4
- /**
5
- * Verify that all expectations on the given mock have been met.
6
- *
7
- * @throws Will throw if there are remaining expectations that were set
8
- * using `when` and that weren't met.
9
- *
10
- * @throws Will throw if any unexpected calls happened. Normally those
11
- * calls throw on their own, but the error might be caught by the code
12
- * being tested.
13
- *
14
- * @example
15
- * const fn = mock<() => number>();
16
- *
17
- * when(() => fn()).thenReturn(23);
18
- *
19
- * verify(fn); // throws
20
- */
21
- export declare const verify: <T>(mock: Mock<T>) => void;
22
- /**
23
- * Verify all existing mocks.
24
- *
25
- * @see verify
26
- */
27
- export declare const verifyAll: () => void;
@@ -1,26 +0,0 @@
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
- */
10
- export interface ExpectationBuilder {
11
- setProperty: (prop: Property) => void;
12
- setArgs: (args: unknown[] | undefined) => void;
13
- finish: (returnValue: ReturnValue) => Expectation;
14
- }
15
- export type ExpectationFactory = (property: Property, args: any[] | undefined, returnValue: ReturnValue, concreteMatcher: ConcreteMatcher, exactParams: boolean) => Expectation;
16
- export declare class ExpectationBuilderWithFactory implements ExpectationBuilder {
17
- private createExpectation;
18
- private concreteMatcher;
19
- private exactParams;
20
- private args;
21
- private property;
22
- constructor(createExpectation: ExpectationFactory, concreteMatcher: ConcreteMatcher, exactParams: boolean);
23
- setProperty(value: Property): void;
24
- setArgs(value: unknown[] | undefined): void;
25
- finish(returnValue: ReturnValue): Expectation;
26
- }