strong-mock 7.2.0 → 8.0.0-beta.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/expectation/matcher.ts","../src/expectation/expectation.ts","../src/print.ts","../src/errors.ts","../src/proxy.ts","../src/mock/map.ts","../src/mock/stub.ts","../src/expectation/repository/base-repository.ts","../src/expectation/repository/strong-repository.ts","../src/expectation/strong-expectation.ts","../src/when/pending-expectation.ts","../src/expectation/it.ts","../src/mock/defaults.ts","../src/mock/mock.ts","../src/return/invocation-count.ts","../src/return/returns.ts","../src/when/when.ts","../src/verify/reset.ts","../src/verify/verify.ts"],"sourcesContent":["export const MATCHER_SYMBOL = Symbol('matcher');\n\nexport type Matcher = {\n /**\n * Will be called with a value to match against.\n */\n matches: (arg: any) => boolean;\n\n [MATCHER_SYMBOL]: boolean;\n\n /**\n * Used by `pretty-format`.\n */\n toJSON(): string;\n};\n\n/**\n * This takes the shape of T to satisfy call sites, but strong-mock will only\n * care about the matcher type.\n */\nexport type TypeMatcher<T> = T & Matcher;\n\n/**\n * Used to test if an expectation on an argument is a custom matcher.\n */\nexport function isMatcher(f: unknown): f is Matcher {\n return !!(f && (<Matcher>f)[MATCHER_SYMBOL]);\n}\n","import { Property } from '../proxy';\nimport { Matcher } from './matcher';\n\nexport type ReturnValue = {\n value: any;\n isPromise?: boolean;\n isError?: boolean;\n};\n\n/**\n * Compare received arguments against matchers.\n */\nexport interface Expectation {\n property: Property;\n\n /**\n * `undefined` means this is a property expectation.\n * `[]` means this is a function call with no arguments.\n */\n args: Matcher[] | undefined;\n\n returnValue: ReturnValue;\n\n min: number;\n\n max: number;\n\n /**\n * How many times should this expectation match?\n */\n setInvocationCount(min: number, max: number): void;\n\n matches(args: any[] | undefined): boolean;\n\n /**\n * Used by `pretty-format`.\n */\n toJSON(): string;\n}\n\n/**\n * Special symbol denoting the call of a function.\n */\nexport const ApplyProp = Symbol('apply');\n","import { EXPECTED_COLOR, printExpected } from 'jest-matcher-utils';\nimport { ApplyProp, Expectation, ReturnValue } from './expectation/expectation';\nimport { isMatcher } from './expectation/matcher';\nimport { Property } from './proxy';\n\nexport const printProperty = (property: Property) => {\n if (property === ApplyProp) {\n return '';\n }\n\n if (typeof property === 'symbol') {\n return `[${property.toString()}]`;\n }\n\n return `.${property}`;\n};\n\nexport const printArg = (arg: unknown): string =>\n // Call toJSON on matchers directly to avoid wrapping them in quotes.\n isMatcher(arg) ? arg.toJSON() : printExpected(arg);\n\nexport const printCall = (property: Property, args: any[]) => {\n const prettyArgs = args.map((arg) => printArg(arg)).join(', ');\n const prettyProperty = printProperty(property);\n\n return `${prettyProperty}(${prettyArgs})`;\n};\n\nexport const printReturns = (\n { isError, isPromise, value }: ReturnValue,\n min: number,\n max: number\n) => {\n let thenPrefix = '';\n\n if (isPromise) {\n if (isError) {\n thenPrefix += 'thenReject';\n } else {\n thenPrefix += 'thenResolve';\n }\n } else if (isError) {\n thenPrefix += 'thenThrow';\n } else {\n thenPrefix += 'thenReturn';\n }\n\n return `.${thenPrefix}(${printExpected(value)}).between(${min}, ${max})`;\n};\n\nexport const printWhen = (property: Property, args: any[] | undefined) => {\n if (args) {\n return `when(${EXPECTED_COLOR(`mock${printCall(property, args)}`)})`;\n }\n\n return `when(${EXPECTED_COLOR(`mock${printProperty(property)}`)})`;\n};\n\nexport const printExpectation = (\n property: Property,\n args: any[] | undefined,\n returnValue: ReturnValue,\n min: number,\n max: number\n) => `${printWhen(property, args)}${printReturns(returnValue, min, max)}`;\n\nexport const printRemainingExpectations = (expectations: Expectation[]) =>\n expectations.length\n ? `Remaining unmet expectations:\n - ${expectations.map((e) => e.toJSON()).join('\\n - ')}`\n : 'There are no remaining unmet expectations.';\n","import { EXPECTED_COLOR } from 'jest-matcher-utils';\nimport { Expectation } from './expectation/expectation';\nimport { CallMap } from './expectation/repository/expectation-repository';\nimport { printCall, printProperty, printRemainingExpectations } from './print';\nimport { Property } from './proxy';\nimport { PendingExpectation } from './when/pending-expectation';\n\nexport class UnfinishedExpectation extends Error {\n constructor(pendingExpectation: PendingExpectation) {\n super(`There is an unfinished pending expectation:\n\n${pendingExpectation.toJSON()}\n\nPlease finish it by setting a return value even if the value\nis undefined.`);\n }\n}\n\nexport class MissingWhen extends Error {\n constructor() {\n super(`You tried setting a return value without an expectation.\n\nEvery call to set a return value must be preceded by an expectation.`);\n }\n}\n\nexport class UnexpectedAccess extends Error {\n constructor(property: Property, expectations: Expectation[]) {\n super(`Didn't expect ${EXPECTED_COLOR(\n `mock${printProperty(property)}`\n )} to be accessed.\n\nIf you expect this property to be accessed then please\nset an expectation for it.\n\n${printRemainingExpectations(expectations)}`);\n }\n}\n\nexport class UnexpectedCall extends Error {\n constructor(property: Property, args: any[], expectations: Expectation[]) {\n super(`Didn't expect ${EXPECTED_COLOR(\n `mock${printCall(property, args)}`\n )} to be called.\n\n${printRemainingExpectations(expectations)}`);\n }\n}\n\nexport class NotAMock extends Error {\n constructor() {\n super(`We couldn't find the mock.\n\nMake sure you're passing in an actual mock.`);\n }\n}\n\nexport class UnmetExpectations extends Error {\n constructor(expectations: Expectation[]) {\n super(`There are unmet expectations:\n\n - ${expectations.map((e) => e.toJSON()).join('\\n - ')}`);\n }\n}\n\n/**\n * Merge property accesses and method calls for the same property\n * into a single call.\n *\n * @example\n * mergeCalls({ foo: [{ arguments: undefined }, { arguments: [1, 2, 3] }] }\n * // returns { foo: [{ arguments: [1, 2, 3] } }\n */\nconst mergeCalls = (callMap: CallMap): CallMap =>\n new Map(\n Array.from(callMap.entries()).map(([property, calls]) => {\n const hasMethodCalls = calls.some((call) => call.arguments);\n const hasPropertyAccesses = calls.some((call) => !call.arguments);\n\n if (hasMethodCalls && hasPropertyAccesses) {\n return [property, calls.filter((call) => call.arguments)];\n }\n\n return [property, calls];\n })\n );\n\nexport class UnexpectedCalls extends Error {\n constructor(unexpectedCalls: CallMap, expectations: Expectation[]) {\n const printedCalls = Array.from(mergeCalls(unexpectedCalls).entries())\n .map(([property, calls]) =>\n calls\n .map((call) =>\n call.arguments\n ? EXPECTED_COLOR(`mock${printCall(property, call.arguments)}`)\n : EXPECTED_COLOR(`mock${printProperty(property)}`)\n )\n .join('\\n - ')\n )\n .join('\\n - ');\n\n super(`The following calls were unexpected:\n\n - ${printedCalls}\n\n${printRemainingExpectations(expectations)}`);\n }\n}\n\nexport class NestedWhen extends Error {\n constructor(parentProp: Property, childProp: Property) {\n const snippet = `\nconst parentMock = mock<T1>();\nconst childMock = mock<T2>();\n\nwhen(() => childMock${printProperty(childProp)}).thenReturn(...);\nwhen(() => parentMock${printProperty(parentProp)}).thenReturn(childMock)\n`;\n\n super(\n `Setting an expectation on a nested property is not supported.\n\nYou can return an object directly when the first property is accessed,\nor you can even return a separate mock:\n${snippet}`\n );\n }\n}\n","import { Mock } from './mock/mock';\n\nexport type Property = string | symbol;\n\nexport interface ProxyTraps {\n /**\n * Called when accessing any property on an object, except for\n * `.call`, `.apply` and `.bind`.\n */\n property: (property: Property) => unknown;\n\n /**\n * Called when calling a function.\n *\n * @example\n * ```\n * fn(...args)\n * ```\n *\n * @example\n * ```\n * fn.call(this, ...args)\n * ```\n *\n * @example\n * ```\n * fn.apply(this, [...args])\n * ```\n *\n * @example\n * ```\n * Reflect.apply(fn, this, [...args])\n * ```\n */\n apply: (args: any[]) => unknown;\n\n /**\n * Called when getting the proxy's own enumerable keys.\n *\n * @example\n * ```\n * Object.keys(proxy);\n * ```\n *\n * @example\n * ```\n * const foo = { ...proxy };\n * ```\n */\n ownKeys: () => Property[];\n}\n\nexport const createProxy = <T>(traps: ProxyTraps): Mock<T> =>\n // eslint-disable-next-line no-empty-function\n new Proxy(/* istanbul ignore next */ () => {}, {\n get: (target, prop: string | symbol) => {\n if (prop === 'bind') {\n return (thisArg: any, ...args: any[]) =>\n (...moreArgs: any[]) =>\n traps.apply([...args, ...moreArgs]);\n }\n\n if (prop === 'apply') {\n return (thisArg: any, args: any[] | undefined) =>\n traps.apply(args || []);\n }\n\n if (prop === 'call') {\n return (thisArg: any, ...args: any[]) => traps.apply(args);\n }\n\n return traps.property(prop);\n },\n\n apply: (target, thisArg: any, args: any[]) => traps.apply(args),\n\n ownKeys: () => traps.ownKeys(),\n\n getOwnPropertyDescriptor(\n target: () => void,\n prop: string | symbol\n ): PropertyDescriptor | undefined {\n const keys = traps.ownKeys();\n\n if (keys.includes(prop)) {\n return {\n configurable: true,\n enumerable: true,\n };\n }\n\n return undefined;\n },\n }) as unknown as Mock<T>;\n","import { NotAMock } from '../errors';\nimport { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { PendingExpectation } from '../when/pending-expectation';\nimport { Mock } from './mock';\n\n/**\n * Since `when` doesn't receive the mock subject (because we can't make it\n * consistently return it from `mock()`, `mock.foo` and `mock.bar()`) we need\n * to store a global state for the currently active mock.\n *\n * We also want to throw in the following case:\n *\n * ```\n * when(() => mock()) // forgot returns here\n * when(() => mock()) // should throw\n * ```\n *\n * For that reason we can't just store the currently active mock, but also\n * whether we finished the expectation or not.\n */\nlet activeMock: Mock<any> | undefined;\n\nexport const setActiveMock = (mock: Mock<any>) => {\n activeMock = mock;\n};\n\nexport const clearActiveMock = () => {\n activeMock = undefined;\n};\n\nexport const getActiveMock = (): Mock<any> => activeMock;\n\ntype MockState = {\n repository: ExpectationRepository;\n pendingExpectation: PendingExpectation;\n};\n\n/**\n * Store a global map of all mocks created and their state.\n *\n * This is needed because we can't reliably pass the state between `when`\n * and `thenReturn`.\n */\nconst mockMap = new Map<Mock<any>, MockState>();\n\nexport const getMockState = (mock: Mock<any>): MockState => {\n if (mockMap.has(mock)) {\n return mockMap.get(mock)!;\n }\n\n throw new NotAMock();\n};\n\nexport const setMockState = (mock: Mock<any>, state: MockState): void => {\n mockMap.set(mock, state);\n};\n\nexport const getAllMocks = (): [Mock<any>, MockState][] =>\n Array.from(mockMap.entries());\n","import { NestedWhen } from '../errors';\nimport { ApplyProp, ReturnValue } from '../expectation/expectation';\nimport { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { createProxy, Property } from '../proxy';\nimport { PendingExpectation } from '../when/pending-expectation';\nimport { setActiveMock } from './map';\nimport { Mock } from './mock';\n\n/**\n * Return the expectation's return value.\n *\n * If the value is an error then throw it.\n *\n * If the value is a promise then resolve/reject it.\n */\nexport const returnOrThrow = ({ isError, isPromise, value }: ReturnValue) => {\n if (isError) {\n if (isPromise) {\n return Promise.reject(value);\n }\n\n if (value instanceof Error) {\n throw value;\n }\n\n throw new Error(value);\n }\n\n if (isPromise) {\n return Promise.resolve(value);\n }\n\n return value;\n};\n\nexport const createStub = <T>(\n repo: ExpectationRepository,\n pendingExpectation: PendingExpectation,\n isRecording: () => boolean = () => true\n): Mock<T> => {\n const stub = createProxy<T>({\n property: (property) => {\n if (!isRecording()) {\n return returnOrThrow(repo.get(property));\n }\n\n setActiveMock(stub);\n\n pendingExpectation.start(repo);\n // eslint-disable-next-line no-param-reassign\n pendingExpectation.property = property;\n\n return createProxy({\n property: (childProp: Property) => {\n pendingExpectation.clear();\n throw new NestedWhen(property, childProp);\n },\n apply: (args: any[]) => {\n // eslint-disable-next-line no-param-reassign\n pendingExpectation.args = args;\n },\n ownKeys: () => {\n throw new Error('Spreading during an expectation is not supported.');\n },\n });\n },\n apply: (args: any[]) => {\n if (!isRecording()) {\n const fn = repo.get(ApplyProp);\n\n // This is not using `returnOrThrow` because the repo will use it.\n return fn.value(...args);\n }\n\n setActiveMock(stub);\n\n pendingExpectation.start(repo);\n // eslint-disable-next-line no-param-reassign\n pendingExpectation.property = ApplyProp;\n // eslint-disable-next-line no-param-reassign\n pendingExpectation.args = args;\n\n return undefined;\n },\n ownKeys: () => {\n if (!isRecording()) {\n return repo.getAllProperties();\n }\n\n throw new Error('Spreading during an expectation is not supported.');\n },\n });\n\n return stub;\n};\n","import { returnOrThrow } from '../../mock/stub';\nimport { Property } from '../../proxy';\nimport { ApplyProp, Expectation, ReturnValue } from '../expectation';\nimport { MATCHER_SYMBOL } from '../matcher';\nimport { CallMap, ExpectationRepository } from './expectation-repository';\n\nexport type CountableExpectation = {\n expectation: Expectation;\n matchCount: number;\n};\n\nexport abstract class BaseRepository implements ExpectationRepository {\n protected readonly expectations = new Map<Property, CountableExpectation[]>();\n\n private readonly expectedCallStats: CallMap = new Map();\n\n private readonly unexpectedCallStats: CallMap = new Map();\n\n add(expectation: Expectation): void {\n const { property } = expectation;\n\n const expectations = this.expectations.get(property) || [];\n\n this.expectations.set(property, [\n ...expectations,\n {\n expectation,\n matchCount: 0,\n },\n ]);\n }\n\n clear(): void {\n this.expectations.clear();\n this.expectedCallStats.clear();\n this.unexpectedCallStats.clear();\n }\n\n get(property: Property): ReturnValue {\n const expectations = this.expectations.get(property);\n\n if (expectations && expectations.length) {\n // We record that an expected property access has happened, but an\n // unexpected call could still happen later.\n this.recordExpected(property, undefined);\n\n const propertyExpectation = expectations.find((e) =>\n e.expectation.matches(undefined)\n );\n\n if (propertyExpectation) {\n this.countAndConsume(propertyExpectation);\n\n return propertyExpectation.expectation.returnValue;\n }\n\n return {\n value: (...args: any[]) => {\n const callExpectation = expectations.find((e) =>\n e.expectation.matches(args)\n );\n\n if (callExpectation) {\n this.recordExpected(property, args);\n this.countAndConsume(callExpectation);\n\n // TODO: this is duplicated in stub\n return returnOrThrow(callExpectation.expectation.returnValue);\n }\n\n this.recordUnexpected(property, args);\n return this.getValueForUnexpectedCall(property, args);\n },\n };\n }\n\n switch (property) {\n case 'toString':\n return { value: () => 'mock' };\n case '@@toStringTag':\n case Symbol.toStringTag:\n case 'name':\n return { value: 'mock' };\n\n // pretty-format\n case '$$typeof':\n case 'constructor':\n case '@@__IMMUTABLE_ITERABLE__@@':\n case '@@__IMMUTABLE_RECORD__@@':\n return { value: null };\n\n case MATCHER_SYMBOL:\n return { value: false };\n\n case ApplyProp:\n return {\n value: (...args: any[]) => {\n this.recordUnexpected(property, args);\n return this.getValueForUnexpectedCall(property, args);\n },\n };\n default:\n this.recordUnexpected(property, undefined);\n return this.getValueForUnexpectedAccess(property);\n }\n }\n\n getAllProperties(): Property[] {\n return Array.from(this.expectations.keys());\n }\n\n getCallStats() {\n return {\n expected: this.expectedCallStats,\n unexpected: this.unexpectedCallStats,\n };\n }\n\n getUnmet(): Expectation[] {\n return ([] as Expectation[]).concat(\n ...Array.from(this.expectations.values()).map((expectations) =>\n expectations\n .filter((e) => e.expectation.min > e.matchCount)\n .map((e) => e.expectation)\n )\n );\n }\n\n /**\n * We got a method call that doesn't match any expectation,\n * what should we return?\n */\n protected abstract getValueForUnexpectedCall(\n property: Property,\n args: any[]\n ): any;\n\n /**\n * We got a property access that doesn't match any expectation,\n * what should we return?\n */\n protected abstract getValueForUnexpectedAccess(\n property: Property\n ): ReturnValue;\n\n protected abstract consumeExpectation(\n expectation: CountableExpectation\n ): void;\n\n /**\n * Record an expected property access/method call.\n */\n private recordExpected(property: Property, args: any[] | undefined) {\n const calls = this.expectedCallStats.get(property) || [];\n\n this.expectedCallStats.set(property, [...calls, { arguments: args }]);\n }\n\n /**\n * Record an unexpected property access/method call.\n */\n private recordUnexpected(property: Property, args: any[] | undefined) {\n const calls = this.unexpectedCallStats.get(property) || [];\n\n this.unexpectedCallStats.set(property, [...calls, { arguments: args }]);\n }\n\n private countAndConsume(expectation: CountableExpectation) {\n // eslint-disable-next-line no-param-reassign\n expectation.matchCount++;\n\n this.consumeExpectation(expectation);\n }\n}\n","import { BaseRepository, CountableExpectation } from './base-repository';\nimport { UnexpectedAccess, UnexpectedCall } from '../../errors';\nimport { Property } from '../../proxy';\n\n/**\n * Throw if no expectation matches.\n */\nexport class StrongRepository extends BaseRepository {\n protected consumeExpectation(expectation: CountableExpectation): void {\n const { property, max } = expectation.expectation;\n\n const expectations = this.expectations.get(property)!;\n\n if (expectation.matchCount === max) {\n this.expectations.set(\n property,\n expectations.filter((e) => e !== expectation)\n );\n }\n }\n\n protected getValueForUnexpectedCall(property: Property, args: any[]): never {\n throw new UnexpectedCall(property, args, this.getUnmet());\n }\n\n protected getValueForUnexpectedAccess(property: Property): never {\n throw new UnexpectedAccess(property, this.getUnmet());\n }\n}\n","import { printExpectation } from '../print';\nimport { Property } from '../proxy';\nimport { Expectation, ReturnValue } from './expectation';\nimport { Matcher } from './matcher';\n\n/**\n * Matches a call with more parameters than expected because it is assumed the\n * compiler will check that those parameters are optional.\n *\n * @example\n * new StrongExpectation(\n * 'bar',\n * deepEquals([1, 2, 3]),\n * 23\n * ).matches('bar', [1, 2, 3]) === true;\n */\nexport class StrongExpectation implements Expectation {\n private matched = 0;\n\n public min: number = 1;\n\n public max: number = 1;\n\n constructor(\n public property: Property,\n public args: Matcher[] | undefined,\n public returnValue: ReturnValue\n ) {}\n\n setInvocationCount(min: number, max = 1) {\n this.min = min;\n this.max = max;\n }\n\n matches(args: any[] | undefined): boolean {\n if (!this.matchesArgs(args)) {\n return false;\n }\n\n this.matched++;\n\n return this.max === 0 || this.matched <= this.max;\n }\n\n isUnmet(): boolean {\n return this.matched < this.min;\n }\n\n private matchesArgs(received: any[] | undefined) {\n if (this.args === undefined) {\n return !received;\n }\n\n if (!received) {\n return false;\n }\n\n return this.args.every((arg, i) => arg.matches(received[i]));\n }\n\n toJSON() {\n return printExpectation(\n this.property,\n this.args,\n this.returnValue,\n this.min,\n this.max\n );\n }\n}\n","import { MissingWhen, UnfinishedExpectation } from '../errors';\nimport { Expectation, ReturnValue } from '../expectation/expectation';\nimport { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { printWhen } from '../print';\nimport { Property } from '../proxy';\n\nexport type ExpectationFactory = (\n property: Property,\n args: any[] | undefined,\n returnValue: ReturnValue\n) => Expectation;\n\nexport interface PendingExpectation {\n // TODO: get rid of repo\n start(repo: ExpectationRepository): void;\n\n finish(returnValue: ReturnValue): Expectation;\n\n clear(): void;\n\n property: Property;\n\n args: any[] | undefined;\n\n /**\n * Used by `pretty-format`.\n */\n toJSON(): string;\n}\n\nexport class RepoSideEffectPendingExpectation implements PendingExpectation {\n private _repo: ExpectationRepository | undefined;\n\n private _args: any[] | undefined;\n\n private _property: Property = '';\n\n constructor(private createExpectation: ExpectationFactory) {}\n\n start(repo: ExpectationRepository) {\n if (this._repo) {\n throw new UnfinishedExpectation(this);\n }\n\n this.clear();\n\n this._repo = repo;\n }\n\n set property(value: Property) {\n this._property = value;\n }\n\n set args(value: any[] | undefined) {\n this._args = value;\n }\n\n finish(returnValue: ReturnValue): Expectation {\n if (!this._repo) {\n throw new MissingWhen();\n }\n\n const expectation = this.createExpectation(\n this._property,\n this._args,\n returnValue\n );\n this._repo.add(expectation);\n\n this.clear();\n\n return expectation;\n }\n\n clear() {\n this._repo = undefined;\n this._args = undefined;\n this._property = '';\n }\n\n toJSON() {\n return printWhen(this._property, this._args);\n }\n}\n","import { printExpected } from 'jest-matcher-utils';\nimport {\n isEqual,\n isMatchWith,\n isObjectLike,\n isUndefined,\n omitBy,\n} from 'lodash';\nimport { printArg } from '../print';\nimport { isMatcher, Matcher, MATCHER_SYMBOL, TypeMatcher } from './matcher';\n\n/**\n * Match a custom predicate.\n *\n * @param cb Will receive the value and returns whether it matches.\n * @param toJSON An optional function that should return a string that will be\n * used when the matcher needs to be printed in an error message. By default,\n * it stringifies `cb`.\n *\n * @example\n * const fn = mock<(x: number) => number>();\n * when(() => fn(It.matches(x => x >= 0))).returns(42);\n *\n * fn(2) === 42\n * fn(-1) // throws\n */\nconst matches = <T>(\n cb: (actual: T) => boolean,\n { toJSON = () => `matches(${cb.toString()})` }: { toJSON?: () => string } = {}\n): TypeMatcher<T> => {\n const matcher: Matcher = {\n [MATCHER_SYMBOL]: true,\n matches: (arg: T) => cb(arg),\n toJSON,\n };\n\n return matcher as any;\n};\n\nconst removeUndefined = (object: any): any => {\n if (Array.isArray(object)) {\n return object.map((x) => removeUndefined(x));\n }\n\n if (!isObjectLike(object)) {\n return object;\n }\n\n return omitBy(object, isUndefined);\n};\n\n/**\n * Compare values using deep equality.\n *\n * @param expected\n * @param strict By default, this matcher will treat a missing key in an object\n * and a key with the value `undefined` as not equal. It will also consider\n * non `Object` instances with different constructors as not equal. Setting\n * this to `false` will consider the objects in both cases as equal.\n *\n * @see It.is A matcher that uses strict equality.\n */\nconst deepEquals = <T>(\n expected: T,\n { strict = true }: { strict?: boolean } = {}\n): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (strict) {\n return isEqual(actual, expected);\n }\n\n return isEqual(removeUndefined(actual), removeUndefined(expected));\n },\n { toJSON: () => printArg(expected) }\n );\n\n/**\n * Compare values using `Object.is`.\n *\n * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n *\n * @see It.deepEquals A matcher that uses deep equality.\n */\nconst is = <T = unknown>(expected: T): TypeMatcher<T> =>\n matches((actual) => Object.is(actual, expected), {\n toJSON: () => `${printExpected(expected)}`,\n });\n\n/**\n * Match any value, including `undefined` and `null`.\n *\n * @example\n * const fn = mock<(x: number, y: string) => number>();\n * when(() => fn(It.isAny(), It.isAny())).thenReturn(1);\n *\n * fn(23, 'foobar') === 1\n */\nconst isAny = (): TypeMatcher<any> =>\n matches(() => true, { toJSON: () => 'anything' });\n\ntype DeepPartial<T> = T extends object\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T;\n\n/**\n * Recursively match an object.\n *\n * Supports nested matcher.\n *\n * @param partial An optional subset of the expected objected.\n *\n * @example\n * const fn = mock<(foo: { x: number, y: number }) => number>();\n * when(() => fn(It.isObject({ x: 23 }))).returns(42);\n *\n * fn({ x: 100, y: 200 }) // throws\n * fn({ x: 23, y: 200 }) // returns 42\n *\n * @example\n * It.isObject({ foo: It.isString() })\n */\nconst isObject = <T extends object, K extends DeepPartial<T>>(\n partial?: K\n): TypeMatcher<T> =>\n matches(\n (actual) =>\n isMatchWith(actual, partial || {}, (argValue, partialValue) => {\n if (isMatcher(partialValue)) {\n return partialValue.matches(argValue);\n }\n\n // Let lodash handle it otherwise.\n return undefined;\n }),\n { toJSON: () => (partial ? `object(${printExpected(partial)})` : 'object') }\n );\n\n/**\n * Match any number.\n *\n * @example\n * const fn = mock<(x: number) => number>();\n * when(() => fn(It.isNumber())).returns(42);\n *\n * fn(20.5) === 42\n * fn(NaN) // throws\n */\nconst isNumber = (): TypeMatcher<number> =>\n matches((actual) => typeof actual === 'number' && !Number.isNaN(actual), {\n toJSON: () => 'number',\n });\n\n/**\n * Match a string, potentially by a pattern.\n *\n * @param matching The string has to match this RegExp.\n * @param containing The string has to contain this substring.\n *\n * @example\n * const fn = mock<(x: string, y: string) => number>();\n * when(() => fn(It.isString(), It.isString({ containing: 'bar' }))).returns(42);\n *\n * fn('foo', 'baz') // throws\n * fn('foo', 'bar') === 42\n */\nconst isString = ({\n matching,\n containing,\n}: { matching?: RegExp; containing?: string } = {}): TypeMatcher<string> => {\n if (matching && containing) {\n throw new Error('You can only pass `matching` or `containing`, not both.');\n }\n\n return matches(\n (actual) => {\n if (typeof actual !== 'string') {\n return false;\n }\n\n if (containing) {\n return actual.indexOf(containing) !== -1;\n }\n\n return matching?.test(actual) ?? true;\n },\n {\n toJSON: () =>\n containing || matching\n ? `string(${printExpected(containing || matching)})`\n : 'string',\n }\n );\n};\n\n/**\n * Match an array.\n *\n * Supports nested matchers.\n *\n * @param containing If given, the matched array has to contain ALL of these\n * elements in ANY order.\n *\n * @example\n * const fn = mock<(arr: number[]) => number>();\n * when(() => fn(It.isArray())).thenReturn(1);\n * when(() => fn(It.isArray([2, 3]))).thenReturn(2);\n *\n * fn({ length: 1, 0: 42 }) // throws\n * fn([]) === 1\n * fn([3, 2, 1]) === 2\n *\n * @example\n * It.isArray([It.isString({ containing: 'foobar' })])\n */\nconst isArray = <T extends any[]>(containing?: T): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (!Array.isArray(actual)) {\n return false;\n }\n\n if (!containing) {\n return true;\n }\n\n return containing.every(\n (x) =>\n actual.find((y) => {\n if (isMatcher(x)) {\n return x.matches(y);\n }\n\n return deepEquals(x).matches(y);\n }) !== undefined\n );\n },\n {\n toJSON: () =>\n containing ? `array(${printExpected(containing)})` : 'array',\n }\n );\n\n/**\n * Matches anything and stores the received value.\n *\n * This should not be needed for most cases, but can be useful if you need\n * access to a complex argument outside the expectation e.g. to test a\n * callback.\n *\n * @param name If given, this name will be printed in error messages.\n *\n * @example\n * const fn = mock<(cb: (value: number) => number) => void>();\n * const matcher = It.willCapture();\n * when(() => fn(matcher)).thenReturn();\n *\n * fn(x => x + 1);\n * matcher.value?.(3) === 4\n */\nconst willCapture = <T = unknown>(\n name?: string\n): TypeMatcher<T> & { value: T | undefined } => {\n let capturedValue: T | undefined;\n\n const matcher: Matcher & { value: T | undefined } = {\n [MATCHER_SYMBOL]: true,\n matches: (actual) => {\n capturedValue = actual;\n\n return true;\n },\n toJSON: () => name ?? 'captures',\n get value(): T | undefined {\n return capturedValue;\n },\n };\n\n return matcher as any;\n};\n\n/**\n * Contains argument matchers that can be used to ignore arguments in an\n * expectation or to match complex arguments.\n */\nexport const It = {\n matches,\n deepEquals,\n is,\n isAny,\n isObject,\n isNumber,\n isString,\n isArray,\n willCapture,\n};\n","import { It } from '../expectation/it';\nimport { Matcher } from '../expectation/matcher';\n\nexport type StrongMockDefaults = {\n /**\n * The matcher that will be used when one isn't specified explicitly.\n *\n * @param expected The non matcher expected value.\n *\n * @example\n * StrongMock.setDefaults({\n * matcher: () => It.matches(() => true)\n * });\n *\n * when(() => fn('value')).thenReturn(true);\n *\n * fn('not-value') === true;\n */\n matcher: <T>(expected: T) => Matcher;\n};\n\nconst defaults: StrongMockDefaults = {\n matcher: It.deepEquals,\n};\n\nexport let currentDefaults: StrongMockDefaults = defaults;\n\n/**\n * Override strong-mock's defaults.\n *\n * @param newDefaults These will be applied to the library defaults. Multiple\n * calls don't stack e.g. calling this with `{}` will clear any previously\n * applied defaults.\n */\nexport const setDefaults = (newDefaults: Partial<StrongMockDefaults>): void => {\n currentDefaults = {\n ...defaults,\n ...newDefaults,\n };\n};\n","import { isMatcher } from '../expectation/matcher';\nimport { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { StrongRepository } from '../expectation/repository/strong-repository';\nimport { StrongExpectation } from '../expectation/strong-expectation';\nimport {\n ExpectationFactory,\n RepoSideEffectPendingExpectation,\n} from '../when/pending-expectation';\nimport { currentDefaults } from './defaults';\nimport { setMockState } from './map';\nimport { createStub } from './stub';\n\nexport type Mock<T> = T;\n\nconst strongExpectationFactory: ExpectationFactory = (\n property,\n args,\n returnValue\n) =>\n new StrongExpectation(\n property,\n // Wrap every non-matcher in the default matcher.\n args?.map((arg) => (isMatcher(arg) ? arg : currentDefaults.matcher(arg))),\n returnValue\n );\n\nexport let isRecording = false;\n\nexport const setRecording = (recording: boolean) => {\n isRecording = recording;\n};\n\ninterface MockOptions {\n /**\n * You can provide your own repository to store and find expectations.\n */\n repository?: ExpectationRepository;\n\n /**\n * You can provide your own way of creating expectations.\n */\n expectationFactory?: ExpectationFactory;\n}\n\n/**\n * Create a type safe mock.\n *\n * @see {@link when} Set expectations on the mock using `when`.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * fn() === 23;\n */\nexport const mock = <T>({\n repository = new StrongRepository(),\n expectationFactory = strongExpectationFactory,\n}: MockOptions = {}): Mock<T> => {\n const pendingExpectation = new RepoSideEffectPendingExpectation(\n expectationFactory\n );\n\n const stub = createStub<T>(repository, pendingExpectation, () => isRecording);\n\n setMockState(stub, { repository, pendingExpectation });\n\n return stub;\n};\n","import { Expectation } from '../expectation/expectation';\n\nexport interface InvocationCount {\n /**\n * Expect a call to be made at least `min` times and at most `max` times.\n */\n between(min: number, max: number): void;\n\n /**\n * Expect a call to be made exactly `exact` times.\n *\n * Shortcut for `between(exact, exact)`.\n */\n times(exact: number): void;\n\n /**\n * Expect a call to be made any number of times, including never.\n *\n * Shortcut for `between(0, Infinity)`.\n */\n anyTimes(): void;\n\n /**\n * Expect a call to be made at least `min` times.\n *\n * Shortcut for `between(min, Infinity)`.\n */\n atLeast(min: number): void;\n\n /**\n * Expect a call to be made at most `max` times.\n *\n * Shortcut for `between(0, max)`.\n */\n atMost(max: number): void;\n\n /**\n * Expect a call to be made exactly once.\n *\n * Shortcut for `times(1)`.\n */\n once(): void;\n\n /**\n * Expect a call to be made exactly twice.\n *\n * Shortcut for `times(2)`.\n */\n twice(): void;\n}\n\nexport const createInvocationCount = (\n expectation: Expectation\n): InvocationCount => ({\n between(min: number, max: number) {\n expectation.setInvocationCount(min, max);\n },\n\n /* istanbul ignore next */\n times(exact: number) {\n expectation.setInvocationCount(exact, exact);\n },\n\n /* istanbul ignore next */\n anyTimes(): void {\n expectation.setInvocationCount(0, 0);\n },\n\n /* istanbul ignore next */\n atLeast(min: number) {\n expectation.setInvocationCount(min, Infinity);\n },\n\n /* istanbul ignore next */\n atMost(max: number) {\n expectation.setInvocationCount(0, max);\n },\n\n /* istanbul ignore next */\n once() {\n expectation.setInvocationCount(1, 1);\n },\n\n /* istanbul ignore next */\n twice() {\n expectation.setInvocationCount(2, 2);\n },\n /* eslint-enable no-param-reassign, no-multi-assign */\n});\n","import { ReturnValue } from '../expectation/expectation';\nimport { PendingExpectation } from '../when/pending-expectation';\nimport { createInvocationCount, InvocationCount } from './invocation-count';\n\ntype PromiseStub<R, P> = {\n /**\n * Set the return value for the current call.\n *\n * @param value This needs to be of the same type as the value returned\n * by the call inside `when`.\n *\n * @example\n * when(() => fn()).thenReturn(Promise.resolve(23));\n *\n * @example\n * when(() => fn()).thenReturn(Promise.reject({ foo: 'bar' });\n */\n thenReturn(value: P): InvocationCount;\n\n /**\n * Set the return value for the current call.\n *\n * @param promiseValue This needs to be of the same type as the value inside\n * the promise returned by the `when` callback.\n */\n thenResolve(promiseValue: R): InvocationCount;\n\n /**\n * Make the current call reject with the given error.\n *\n * @param error An `Error` instance. If you want to reject with a non error\n * then use the `thenReturn` method.\n */\n thenReject(error: Error): InvocationCount;\n\n /**\n * Make the current call reject with an error with the given message.\n *\n * @param message Will be wrapped in `new Error()`. If you want to reject\n * with a custom error then pass it here instead of the message. If you\n * want to reject with a non error then use `thenReturn`.\n */\n thenReject(message: string): InvocationCount;\n\n /**\n * Make the current call reject with `new Error()`.\n */\n thenReject(): InvocationCount;\n};\n\ntype NonPromiseStub<R> = {\n /**\n * Set the return value for the current call.\n *\n * @param returnValue This needs to be of the same type as the value returned\n * by the `when` callback.\n */\n thenReturn(returnValue: R): InvocationCount;\n\n /**\n * Make the current call throw the given error.\n *\n * @param error The error instance. If you want to throw a simple `Error`\n * you can pass just the message.\n */\n thenThrow(error: Error): InvocationCount;\n\n /**\n * Make the current call throw an error with the given message.\n *\n * @param message Will be wrapped in `new Error()`. If you want to throw\n * a custom error pass it here instead of the message.\n */\n thenThrow(message: string): InvocationCount;\n\n /**\n * Make the current call throw `new Error()`.\n */\n thenThrow(): InvocationCount;\n};\n\n// Wrap T in a tuple to prevent distribution in case it's a union.\nexport type Stub<T> = [T] extends [Promise<infer U>]\n ? PromiseStub<U, T>\n : NonPromiseStub<T>;\n\n/**\n * Set a return value for the currently pending expectation.\n */\nconst finishPendingExpectation = (\n returnValue: ReturnValue,\n pendingExpectation: PendingExpectation\n) => {\n const finishedExpectation = pendingExpectation.finish(returnValue);\n pendingExpectation.clear();\n\n return createInvocationCount(finishedExpectation);\n};\n\nconst getError = (errorOrMessage: Error | string | undefined): Error => {\n if (typeof errorOrMessage === 'string') {\n return new Error(errorOrMessage);\n }\n\n if (errorOrMessage instanceof Error) {\n return errorOrMessage;\n }\n\n return new Error();\n};\n\nexport const createReturns = <R>(\n pendingExpectation: PendingExpectation\n): Stub<R> => {\n const nonPromiseStub: NonPromiseStub<any> = {\n // TODO: merge this with the promise version\n thenReturn:\n /* istanbul ignore next: because this is overwritten by the promise version */ (\n returnValue: any\n ): InvocationCount =>\n finishPendingExpectation(\n { value: returnValue, isError: false, isPromise: false },\n pendingExpectation\n ),\n thenThrow: (errorOrMessage?: Error | string): InvocationCount =>\n finishPendingExpectation(\n { value: getError(errorOrMessage), isError: true, isPromise: false },\n pendingExpectation\n ),\n };\n\n const promiseStub: PromiseStub<any, any> = {\n thenReturn: (promise: Promise<any>): InvocationCount =>\n finishPendingExpectation(\n {\n value: promise,\n isError: false,\n // We're setting this to false because we can't distinguish between a\n // promise thenReturn and a normal thenReturn.\n isPromise: false,\n },\n pendingExpectation\n ),\n\n thenResolve: (promiseValue: any): InvocationCount =>\n finishPendingExpectation(\n {\n value: promiseValue,\n isError: false,\n isPromise: true,\n },\n pendingExpectation\n ),\n\n thenReject: (errorOrMessage?: Error | string): InvocationCount =>\n finishPendingExpectation(\n {\n value: getError(errorOrMessage),\n isError: true,\n isPromise: true,\n },\n pendingExpectation\n ),\n };\n\n // @ts-expect-error because the return type is a conditional, and we're merging\n // both branches here\n return { ...nonPromiseStub, ...promiseStub };\n};\n","import { getActiveMock, getMockState } from '../mock/map';\nimport { setRecording } from '../mock/mock';\nimport { createReturns, Stub } from '../return/returns';\n\n/**\n * Set an expectation on a mock.\n *\n * The expectation must be finished by setting a return value, even if the value\n * is `undefined`.\n *\n * If a call happens that was not expected then the mock will throw an error.\n * By default, the call is expected to only be made once. Use the invocation\n * count helpers to expect a call multiple times.\n *\n * @param expectation A callback to set the expectation on your mock. The\n * callback must return the value from the mock to properly infer types.\n *\n * @example\n * const fn = mock<() => void>();\n * when(() => fn()).thenReturn(undefined);\n *\n * @example\n * const fn = mock<() => number>();\n * when(() => fn()).thenReturn(42).atMost(3);\n *\n * @example\n * const fn = mock<(x: number) => Promise<number>();\n * when(() => fn(23)).thenResolve(42);\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars\nexport const when = <R>(expectation: () => R): Stub<R> => {\n setRecording(true);\n expectation();\n setRecording(false);\n\n return createReturns<R>(getMockState(getActiveMock()).pendingExpectation);\n};\n","import { getAllMocks, getMockState } from '../mock/map';\nimport { Mock } from '../mock/mock';\n\n/**\n * Remove any remaining expectations on the given mock.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * reset(fn);\n *\n * fn(); // throws\n */\nexport const reset = (mock: Mock<any>): void => {\n getMockState(mock).repository.clear();\n};\n\n/**\n * Reset all existing mocks.\n *\n * @see reset\n */\nexport const resetAll = (): void => {\n getAllMocks().forEach(([mock]) => {\n reset(mock);\n });\n};\n","import { UnexpectedCalls, UnmetExpectations } from '../errors';\nimport { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { getAllMocks, getMockState } from '../mock/map';\nimport { Mock } from '../mock/mock';\n\nexport const verifyRepo = (repository: ExpectationRepository) => {\n const unmetExpectations = repository.getUnmet();\n\n if (unmetExpectations.length) {\n throw new UnmetExpectations(unmetExpectations);\n }\n\n const callStats = repository.getCallStats();\n\n if (callStats.unexpected.size) {\n throw new UnexpectedCalls(callStats.unexpected, unmetExpectations);\n }\n};\n\n/**\n * Verify that all expectations on the given mock have been met.\n *\n * @throws Will throw if there are remaining expectations that were set\n * using `when` and that weren't met.\n *\n * @throws Will throw if any unexpected calls happened. Normally those\n * calls throw on their own, but the error might be caught by the code\n * being tested.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * verify(fn); // throws\n */\nexport const verify = <T>(mock: Mock<T>): void => {\n const { repository } = getMockState(mock);\n\n verifyRepo(repository);\n};\n\n/**\n * Verify all existing mocks.\n *\n * @see verify\n */\nexport const verifyAll = (): void => {\n getAllMocks().forEach(([mock]) => {\n verify(mock);\n });\n};\n"],"names":["MATCHER_SYMBOL","Symbol","isMatcher","f","ApplyProp","printProperty","property","toString","printArg","arg","toJSON","printExpected","printCall","args","prettyArgs","map","join","prettyProperty","printReturns","isError","isPromise","value","min","max","thenPrefix","printWhen","EXPECTED_COLOR","printExpectation","returnValue","printRemainingExpectations","expectations","length","e","UnfinishedExpectation","Error","constructor","pendingExpectation","MissingWhen","UnexpectedAccess","UnexpectedCall","NotAMock","UnmetExpectations","mergeCalls","callMap","Map","Array","from","entries","calls","hasMethodCalls","some","call","arguments","hasPropertyAccesses","filter","UnexpectedCalls","unexpectedCalls","printedCalls","NestedWhen","parentProp","childProp","snippet","createProxy","traps","Proxy","get","target","prop","thisArg","moreArgs","apply","ownKeys","getOwnPropertyDescriptor","keys","includes","configurable","enumerable","undefined","activeMock","setActiveMock","mock","getActiveMock","mockMap","getMockState","has","setMockState","state","set","getAllMocks","returnOrThrow","Promise","reject","resolve","createStub","repo","isRecording","stub","start","clear","fn","getAllProperties","BaseRepository","expectedCallStats","unexpectedCallStats","add","expectation","matchCount","recordExpected","propertyExpectation","find","matches","countAndConsume","callExpectation","recordUnexpected","getValueForUnexpectedCall","toStringTag","getValueForUnexpectedAccess","getCallStats","expected","unexpected","getUnmet","concat","values","consumeExpectation","StrongRepository","StrongExpectation","matched","setInvocationCount","matchesArgs","isUnmet","received","every","i","RepoSideEffectPendingExpectation","createExpectation","_repo","_args","_property","finish","cb","matcher","removeUndefined","object","isArray","x","isObjectLike","omitBy","isUndefined","deepEquals","strict","actual","isEqual","is","Object","isAny","isObject","partial","isMatchWith","argValue","partialValue","isNumber","Number","isNaN","isString","matching","containing","indexOf","test","y","willCapture","name","capturedValue","It","defaults","currentDefaults","setDefaults","newDefaults","strongExpectationFactory","setRecording","recording","repository","expectationFactory","createInvocationCount","between","times","exact","anyTimes","atLeast","Infinity","atMost","once","twice","finishPendingExpectation","finishedExpectation","getError","errorOrMessage","createReturns","nonPromiseStub","thenReturn","thenThrow","promiseStub","promise","thenResolve","promiseValue","thenReject","when","reset","resetAll","forEach","verifyRepo","unmetExpectations","callStats","size","verify","verifyAll"],"mappings":";;;AAAO,MAAMA,cAAc,GAAGC,MAAM,CAAC,SAAD,CAA7B;AAsBP;;;;SAGgBC,UAAUC;AACxB,SAAO,CAAC,EAAEA,CAAC,IAAcA,CAAE,CAACH,cAAD,CAAnB,CAAR;AACD;;ACaD;;;AAGO,MAAMI,SAAS,GAAGH,MAAM,CAAC,OAAD,CAAxB;;ACtCA,MAAMI,aAAa,GAAIC,QAAD;AAC3B,MAAIA,QAAQ,KAAKF,SAAjB,EAA4B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G9B,UAAU,CAAC5D,QAAX,EAA1B;;AAEA,MAAI0F,iBAAiB,CAACnL,MAAtB,EAA8B;AAC5B,UAAM,IAAIU,iBAAJ,CAAsByK,iBAAtB,CAAN;AACD;;AAED,QAAMC,SAAS,GAAG/B,UAAU,CAAC/D,YAAX,EAAlB;;AAEA,MAAI8F,SAAS,CAAC5F,UAAV,CAAqB6F,IAAzB,EAA+B;AAC7B,UAAM,IAAI7J,eAAJ,CAAoB4J,SAAS,CAAC5F,UAA9B,EAA0C2F,iBAA1C,CAAN;AACD;AACF,CAZM;AAcP;;;;;;;;;;;;;;;;;;MAiBaG,MAAM,GAAOrI,IAAJ;AACpB,QAAM;AAAEoG,IAAAA;AAAF,MAAiBjG,YAAY,CAACH,IAAD,CAAnC;AAEAiI,EAAAA,UAAU,CAAC7B,UAAD,CAAV;AACD;AAED;;;;;;MAKakC,SAAS,GAAG;AACvB9H,EAAAA,WAAW,GAAGwH,OAAd,CAAsB,CAAC,CAAChI,IAAD,CAAD;AACpBqI,IAAAA,MAAM,CAACrI,IAAD,CAAN;AACD,GAFD;AAGD;;;;;;;;;;;"}
@@ -0,0 +1,27 @@
1
+ import { Matcher } from '../expectation/matcher';
2
+ export declare type StrongMockDefaults = {
3
+ /**
4
+ * The matcher that will be used when one isn't specified explicitly.
5
+ *
6
+ * @param expected The non matcher expected value.
7
+ *
8
+ * @example
9
+ * StrongMock.setDefaults({
10
+ * matcher: () => It.matches(() => true)
11
+ * });
12
+ *
13
+ * when(() => fn('value')).thenReturn(true);
14
+ *
15
+ * fn('not-value') === true;
16
+ */
17
+ matcher: <T>(expected: T) => Matcher;
18
+ };
19
+ export declare let currentDefaults: StrongMockDefaults;
20
+ /**
21
+ * Override strong-mock's defaults.
22
+ *
23
+ * @param newDefaults These will be applied to the library defaults. Multiple
24
+ * calls don't stack e.g. calling this with `{}` will clear any previously
25
+ * applied defaults.
26
+ */
27
+ export declare const setDefaults: (newDefaults: Partial<StrongMockDefaults>) => void;
@@ -1,6 +1,6 @@
1
1
  import { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import { Mock } from './mock';
3
2
  import { PendingExpectation } from '../when/pending-expectation';
3
+ import { Mock } from './mock';
4
4
  export declare const setActiveMock: (mock: Mock<any>) => void;
5
5
  export declare const clearActiveMock: () => void;
6
6
  export declare const getActiveMock: () => Mock<any>;
@@ -1,6 +1,8 @@
1
1
  import { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
2
  import { ExpectationFactory } from '../when/pending-expectation';
3
3
  export declare type Mock<T> = T;
4
+ export declare let isRecording: boolean;
5
+ export declare const setRecording: (recording: boolean) => void;
4
6
  interface MockOptions {
5
7
  /**
6
8
  * You can provide your own repository to store and find expectations.
@@ -14,15 +16,14 @@ interface MockOptions {
14
16
  /**
15
17
  * Create a type safe mock.
16
18
  *
17
- * Set expectations on the mock using `when` and `thenReturn` and get an
18
- * instance from the mock using `instance`.
19
+ * @see {@link when} Set expectations on the mock using `when`.
19
20
  *
20
21
  * @example
21
22
  * const fn = mock<() => number>();
22
23
  *
23
- * when(fn()).thenReturn(23);
24
+ * when(() => fn()).thenReturn(23);
24
25
  *
25
- * instance(fn) === 23;
26
+ * fn() === 23;
26
27
  */
27
28
  export declare const mock: <T>({ repository, expectationFactory, }?: MockOptions) => T;
28
29
  export {};
@@ -1,4 +1,13 @@
1
+ import { ReturnValue } from '../expectation/expectation';
1
2
  import { ExpectationRepository } from '../expectation/repository/expectation-repository';
2
- import { Mock } from './mock';
3
3
  import { PendingExpectation } from '../when/pending-expectation';
4
- export declare const createStub: <T>(repo: ExpectationRepository, pendingExpectation: PendingExpectation) => T;
4
+ import { Mock } from './mock';
5
+ /**
6
+ * Return the expectation's return value.
7
+ *
8
+ * If the value is an error then throw it.
9
+ *
10
+ * If the value is a promise then resolve/reject it.
11
+ */
12
+ export declare const returnOrThrow: ({ isError, isPromise, value }: ReturnValue) => any;
13
+ export declare const createStub: <T>(repo: ExpectationRepository, pendingExpectation: PendingExpectation, isRecording?: () => boolean) => T;
@@ -1,24 +1,24 @@
1
- import { InvocationCount } from './invocation-count';
2
1
  import { PendingExpectation } from '../when/pending-expectation';
2
+ import { InvocationCount } from './invocation-count';
3
3
  declare type PromiseStub<R, P> = {
4
4
  /**
5
5
  * Set the return value for the current call.
6
6
  *
7
7
  * @param value This needs to be of the same type as the value returned
8
- * by the call inside `when()`.
8
+ * by the call inside `when`.
9
9
  *
10
10
  * @example
11
- * when(fn()).thenReturn(Promise.resolve(23));
11
+ * when(() => fn()).thenReturn(Promise.resolve(23));
12
12
  *
13
13
  * @example
14
- * when(fn()).thenReturn(Promise.reject({ foo: 'bar' });
14
+ * when(() => fn()).thenReturn(Promise.reject({ foo: 'bar' });
15
15
  */
16
16
  thenReturn(value: P): InvocationCount;
17
17
  /**
18
18
  * Set the return value for the current call.
19
19
  *
20
20
  * @param promiseValue This needs to be of the same type as the value inside
21
- * the promise returned by the call inside `when()`.
21
+ * the promise returned by the `when` callback.
22
22
  */
23
23
  thenResolve(promiseValue: R): InvocationCount;
24
24
  /**
@@ -46,7 +46,7 @@ declare type NonPromiseStub<R> = {
46
46
  * Set the return value for the current call.
47
47
  *
48
48
  * @param returnValue This needs to be of the same type as the value returned
49
- * by the call inside `when()`.
49
+ * by the `when` callback.
50
50
  */
51
51
  thenReturn(returnValue: R): InvocationCount;
52
52
  /**
@@ -5,11 +5,11 @@ import { Mock } from '../mock/mock';
5
5
  * @example
6
6
  * const fn = mock<() => number>();
7
7
  *
8
- * when(fn()).thenReturn(23);
8
+ * when(() => fn()).thenReturn(23);
9
9
  *
10
10
  * reset(fn);
11
11
  *
12
- * instance(fn)(); // throws
12
+ * fn(); // throws
13
13
  */
14
14
  export declare const reset: (mock: Mock<any>) => void;
15
15
  /**
@@ -14,7 +14,7 @@ export declare const verifyRepo: (repository: ExpectationRepository) => void;
14
14
  * @example
15
15
  * const fn = mock<() => number>();
16
16
  *
17
- * when(fn()).thenReturn(23);
17
+ * when(() => fn()).thenReturn(23);
18
18
  *
19
19
  * verify(fn); // throws
20
20
  */
@@ -9,18 +9,19 @@ import { Stub } from '../return/returns';
9
9
  * By default, the call is expected to only be made once. Use the invocation
10
10
  * count helpers to expect a call multiple times.
11
11
  *
12
- * @param expectedCall Make a "real" call using the value returned by `mock()`.
12
+ * @param expectation A callback to set the expectation on your mock. The
13
+ * callback must return the value from the mock to properly infer types.
13
14
  *
14
15
  * @example
15
16
  * const fn = mock<() => void>();
16
- * when(fn()).thenReturn(undefined);
17
+ * when(() => fn()).thenReturn(undefined);
17
18
  *
18
19
  * @example
19
20
  * const fn = mock<() => number>();
20
- * when(fn()).thenReturn(42).atMost(3);
21
+ * when(() => fn()).thenReturn(42).atMost(3);
21
22
  *
22
23
  * @example
23
24
  * const fn = mock<(x: number) => Promise<number>();
24
- * when(fn(23)).thenResolve(42);
25
+ * when(() => fn(23)).thenResolve(42);
25
26
  */
26
- export declare const when: <R>(expectedCall: R) => Stub<R>;
27
+ export declare const when: <R>(expectation: () => R) => Stub<R>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strong-mock",
3
- "version": "7.2.0",
3
+ "version": "8.0.0-beta.0",
4
4
  "description": "Simple type safe mocking library",
5
5
  "keywords": [
6
6
  "tdd",
@@ -20,36 +20,34 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
- "scripts": {
24
- "docs": "doctoc --title '**Table of Contents**' README.md",
25
- "build": "yarn run clean && yarn run compile",
26
- "clean": "rm -rf ./dist",
27
- "compile": "rollup -c",
28
- "prepublishOnly": "npm run build",
29
- "release": "standard-version",
30
- "lint": "eslint --ext ts,tsx,js .",
31
- "test": "tdd-buffet test --coverage --config tests/jest.config.js",
32
- "report-coverage": "codecov"
33
- },
34
23
  "dependencies": {
35
- "jest-matcher-utils": "~27.1.0",
24
+ "jest-matcher-utils": "~27.5.0",
36
25
  "lodash": "~4.17.0"
37
26
  },
38
27
  "devDependencies": {
39
- "@nighttrax/eslint-config-ts": "~8.0.0",
28
+ "@nighttrax/eslint-config-ts": "~10.0.0-beta.2",
40
29
  "@tdd-buffet/jest-config": "~4.1.0",
41
30
  "@tdd-buffet/tsconfig": "~1.0.0",
31
+ "@types/jest": "~27.5.0",
32
+ "@types/node": "~17.0.8",
42
33
  "@types/lodash": "~4.14.0",
43
- "codecov": "~3.8.0",
44
- "doctoc": "~2.0.0",
45
- "eslint": "~7.32.0",
46
- "rollup": "~2.56.0",
47
- "rollup-plugin-typescript2": "~0.30.0",
48
- "standard-version": "~9.3.0",
34
+ "doctoc": "~2.2.0",
35
+ "eslint": "~8.19.0",
36
+ "jest": "~27.5.0",
37
+ "microbundle": "~0.15.0",
38
+ "standard-version": "~9.5.0",
49
39
  "strip-ansi": "~6.0.0",
50
40
  "strong-mock": "~6.0.0",
51
- "tdd-buffet": "~3.0.3",
52
- "tslib": "~2.3.1",
53
- "typescript": "~4.4.0"
41
+ "tslib": "~2.4.0",
42
+ "typescript": "~4.7.0"
43
+ },
44
+ "scripts": {
45
+ "docs": "doctoc --title '**Table of Contents**' README.md",
46
+ "build": "pnpm run clean && pnpm run compile",
47
+ "clean": "rm -rf ./dist",
48
+ "compile": "microbundle --no-compress --target node -f cjs --tsconfig tsconfig.build.json src/index.ts",
49
+ "release": "standard-version",
50
+ "lint": "eslint --ext ts,tsx,js .",
51
+ "test": "jest --coverage --config tests/jest.config.js"
54
52
  }
55
- }
53
+ }
package/CHANGELOG.md DELETED
@@ -1,128 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
-
5
- ## [7.2.0](https://github.com/NiGhTTraX/strong-mock/compare/v7.1.2...v7.2.0) (2021-09-06)
6
-
7
-
8
- ### Features
9
-
10
- * Add `It.willCapture` ([987e391](https://github.com/NiGhTTraX/strong-mock/commit/987e3910db4abbce4ca4b65e3c54c32191e30ddd))
11
-
12
- ### [7.1.2](https://github.com/NiGhTTraX/strong-mock/compare/v7.1.1...v7.1.2) (2021-08-28)
13
-
14
-
15
- ### Bug Fixes
16
-
17
- * Allow other strong mocks in expectations ([569815b](https://github.com/NiGhTTraX/strong-mock/commit/569815b26acaff178dab70602ad705e07f352185)), closes [#254](https://github.com/NiGhTTraX/strong-mock/issues/254) [#256](https://github.com/NiGhTTraX/strong-mock/issues/256)
18
- * **deps:** update dependency jest-matcher-utils to ~27.1.0 ([b024ed0](https://github.com/NiGhTTraX/strong-mock/commit/b024ed00ba11d39bc1195a971285136f443a719d))
19
-
20
- ### [7.1.1](https://github.com/NiGhTTraX/strong-mock/compare/v7.1.0...v7.1.1) (2021-08-26)
21
-
22
- ## [7.1.0](https://github.com/NiGhTTraX/strong-mock/compare/v7.0.0...v7.1.0) (2021-06-24)
23
-
24
-
25
- ### Features
26
-
27
- * `thenReject` now lazily creates promise rejection ([01c9995](https://github.com/NiGhTTraX/strong-mock/commit/01c9995c69d00205388da6d7dba2b35d9e70e5b8)), closes [#238](https://github.com/NiGhTTraX/strong-mock/issues/238)
28
-
29
-
30
- ### Bug Fixes
31
-
32
- * Correctly throw error values from method expectations ([a1ad324](https://github.com/NiGhTTraX/strong-mock/commit/a1ad3244f8dfe7ed1e93193479e5cd347f2bf348))
33
-
34
- ## [7.0.0](https://github.com/NiGhTTraX/strong-mock/compare/v6.0.0...v7.0.0) (2021-06-17)
35
-
36
-
37
- ### ⚠ BREAKING CHANGES
38
-
39
- * Node 10 is no longer supported.
40
-
41
- ### Features
42
-
43
- * Allow mock instances to be enumerable ([850223c](https://github.com/NiGhTTraX/strong-mock/commit/850223cbd906297f07923883c554589b5d12ed53)), closes [#235](https://github.com/NiGhTTraX/strong-mock/issues/235)
44
- * Print promise values in error messages ([bc0301f](https://github.com/NiGhTTraX/strong-mock/commit/bc0301f983147d738af657ae285f696cbfa497e3))
45
-
46
-
47
- ### Bug Fixes
48
-
49
- * **deps:** update dependency jest-matcher-utils to ~26.2.0 ([52e9740](https://github.com/NiGhTTraX/strong-mock/commit/52e9740420bf0479e16f00d9f179e99714ae58fd))
50
- * **deps:** update dependency jest-matcher-utils to ~26.3.0 ([b7f483b](https://github.com/NiGhTTraX/strong-mock/commit/b7f483b8e9b3ed4585a81c3a401f7501691e38ad))
51
- * **deps:** update dependency jest-matcher-utils to ~26.4.0 ([3fe4f66](https://github.com/NiGhTTraX/strong-mock/commit/3fe4f663388724dafaa6813fd8ac02e8a0db6960))
52
- * **deps:** update dependency jest-matcher-utils to ~26.5.0 ([b496bcf](https://github.com/NiGhTTraX/strong-mock/commit/b496bcf1386d1586472f6c15f9a6b8be62dc472c))
53
- * **deps:** update dependency jest-matcher-utils to ~26.6.0 ([7e25d8c](https://github.com/NiGhTTraX/strong-mock/commit/7e25d8c84a19b0f1fa06c6d003d3c0a137b8928b))
54
- * **deps:** update dependency jest-matcher-utils to v27 ([ed3740b](https://github.com/NiGhTTraX/strong-mock/commit/ed3740b47247267f21ce1cc6df2b3cf01df5a019))
55
- * **deps:** update dependency lodash to ~4.17.0 ([8c192bc](https://github.com/NiGhTTraX/strong-mock/commit/8c192bc79df3af4400445949eca307d86aafb8f7))
56
-
57
-
58
- ### build
59
-
60
- * Use node 12 ([d30054a](https://github.com/NiGhTTraX/strong-mock/commit/d30054aa2eee48f612737e3d747022c57694d219))
61
-
62
- ## [6.0.0](https://github.com/NiGhTTraX/strong-mock/compare/v5.0.1...v6.0.0) (2020-06-27)
63
-
64
-
65
- ### ⚠ BREAKING CHANGES
66
-
67
- * Rename `isObjectContaining` to `isObject`
68
-
69
- ### Features
70
-
71
- * Add isNumber matcher ([cc5b0a8](https://github.com/NiGhTTraX/strong-mock/commit/cc5b0a8d125c3632f6c6610381b4fc78b8994f7f))
72
- * Add isString ([6d5980f](https://github.com/NiGhTTraX/strong-mock/commit/6d5980fc82479c6a5bc02068e33a2d5ae9b34fda))
73
- * Add It.isArray ([2359b43](https://github.com/NiGhTTraX/strong-mock/commit/2359b43206aa6bbb20e18295ae332700f0f8a3c8))
74
- * Add verifyAll and resetAll ([eef45e0](https://github.com/NiGhTTraX/strong-mock/commit/eef45e054f6818f629b4fcd17673e6323c025c26))
75
- * Improve error message when setting expectation on nested property ([f1ebabe](https://github.com/NiGhTTraX/strong-mock/commit/f1ebabe29cc5388a04c8183c29b205b38d75cf1a))
76
- * Make matching any object easier ([6011775](https://github.com/NiGhTTraX/strong-mock/commit/60117752e8e0a21ff7df4d2dc2daf05b7b94d0c1))
77
- * Support nested matchers ([c3157b1](https://github.com/NiGhTTraX/strong-mock/commit/c3157b1ce9e6b1761a4f3377885ff195c077f9d0))
78
-
79
-
80
- ### Bug Fixes
81
-
82
- * **deps:** update dependency jest-matcher-utils to ~26.1.0 ([7884b7d](https://github.com/NiGhTTraX/strong-mock/commit/7884b7da0871a7a9e8855a328bd05d97546cf162))
83
- * Make isNumber pretty print consistently with other matchers ([bc5f4f8](https://github.com/NiGhTTraX/strong-mock/commit/bc5f4f86855d9090e82f3f13e323a17ff795ec71))
84
- * Make isString pretty print consistently with other matchers ([3b6d9e8](https://github.com/NiGhTTraX/strong-mock/commit/3b6d9e8b0fff14ca43542d267f1f95878adc3f6b))
85
- * Make mocks pretty-format-able ([73200db](https://github.com/NiGhTTraX/strong-mock/commit/73200dbadc8d5a90b8541fcf7394abd343f6dfd8))
86
-
87
- ### [5.0.1](https://github.com/NiGhTTraX/strong-mock/compare/v5.0.0...v5.0.1) (2020-05-07)
88
-
89
-
90
- ### Bug Fixes
91
-
92
- * Clear unexpected calls on `reset()` ([04493f7](https://github.com/NiGhTTraX/strong-mock/commit/04493f7fa7c0814a4a64aaa4671696df57cb2929))
93
-
94
- ## [5.0.0](https://github.com/NiGhTTraX/strong-mock/compare/v5.0.0-beta.1...v5.0.0) (2020-05-07)
95
-
96
-
97
- ### Features
98
-
99
- * Improve error message for `UnexpectedCalls` ([ff8636c](https://github.com/NiGhTTraX/strong-mock/commit/ff8636c871a45a869d2d509120b40914887f554b))
100
-
101
- ## [5.0.0-beta.1](https://github.com/NiGhTTraX/strong-mock/compare/v5.0.0-beta.0...v5.0.0-beta.1) (2020-05-05)
102
-
103
-
104
- ### Bug Fixes
105
-
106
- * Don't mark toString accesses as unexpected ([20247b6](https://github.com/NiGhTTraX/strong-mock/commit/20247b6799f55fda32d72620e5b8571be323ce99))
107
-
108
- ## [5.0.0-beta.0](https://github.com/NiGhTTraX/strong-mock/compare/v4.1.3...v5.0.0-beta.0) (2020-05-05)
109
-
110
-
111
- ### ⚠ BREAKING CHANGES
112
-
113
- * `verify` used to rely on unexpected calls throwing
114
- when they were made. However, the code under test could `try..catch`
115
- that error and never bubble it up to the test. Unless the test
116
- explicitly checked that the SUT was not in an error state, `verify`
117
- would have not been enough to make sure that everything was correct.
118
- Now it throws if any unexpected calls happened.
119
-
120
- ### Features
121
-
122
- * Record unexpected calls ([a87f612](https://github.com/NiGhTTraX/strong-mock/commit/a87f612df7e702e980f1f3271a8585ac6a280c67))
123
- * Throw on unexpected calls when verifying mock ([f68e2f2](https://github.com/NiGhTTraX/strong-mock/commit/f68e2f231f29a5f97c93011241a1f312e8c6f247))
124
-
125
-
126
- ### Bug Fixes
127
-
128
- * **deps:** update dependency jest-matcher-utils to v26 ([5ae654d](https://github.com/NiGhTTraX/strong-mock/commit/5ae654d31205bc554a7f9edae4dd8a5a45b77cc7))
@@ -1,14 +0,0 @@
1
- import { ReturnValue } from '../expectation/expectation';
2
- import { Mock } from '../mock/mock';
3
- /**
4
- * Return the expectation's return value.
5
- *
6
- * If the value is an error then throw it.
7
- *
8
- * If the value is a promise then resolve/reject it.
9
- */
10
- export declare const returnOrThrow: ({ isError, isPromise, value }: ReturnValue) => any;
11
- /**
12
- * Get a real instance from the mock that you can pass to your code under test.
13
- */
14
- export declare const instance: <T>(mock: T) => T;