jest-mock
Advanced tools
Comparing version 26.6.2 to 27.0.0-next.0
@@ -9,44 +9,41 @@ /** | ||
declare type Global = NodeJS.Global; | ||
declare namespace JestMock { | ||
type ModuleMocker = ModuleMockerClass; | ||
type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined'; | ||
type MockFunctionMetadata<T, Y extends Array<unknown>, Type = MockFunctionMetadataType> = { | ||
ref?: number; | ||
members?: Record<string, MockFunctionMetadata<T, Y>>; | ||
mockImpl?: (...args: Y) => T; | ||
name?: string; | ||
refID?: number; | ||
type?: Type; | ||
value?: T; | ||
length?: number; | ||
}; | ||
interface Mock<T, Y extends Array<unknown> = Array<unknown>> extends Function, MockInstance<T, Y> { | ||
new (...args: Y): T; | ||
(...args: Y): T; | ||
} | ||
interface SpyInstance<T, Y extends Array<unknown>> extends MockInstance<T, Y> { | ||
} | ||
interface MockInstance<T, Y extends Array<unknown>> { | ||
_isMockFunction: true; | ||
_protoImpl: Function; | ||
getMockName(): string; | ||
getMockImplementation(): Function | undefined; | ||
mock: MockFunctionState<T, Y>; | ||
mockClear(): this; | ||
mockReset(): this; | ||
mockRestore(): void; | ||
mockImplementation(fn: (...args: Y) => T): this; | ||
mockImplementation(fn: () => Promise<T>): this; | ||
mockImplementationOnce(fn: (...args: Y) => T): this; | ||
mockImplementationOnce(fn: () => Promise<T>): this; | ||
mockName(name: string): this; | ||
mockReturnThis(): this; | ||
mockReturnValue(value: T): this; | ||
mockReturnValueOnce(value: T): this; | ||
mockResolvedValue(value: Unpromisify<T>): this; | ||
mockResolvedValueOnce(value: Unpromisify<T>): this; | ||
mockRejectedValue(value: unknown): this; | ||
mockRejectedValueOnce(value: unknown): this; | ||
} | ||
export declare type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined'; | ||
export declare type MockFunctionMetadata<T, Y extends Array<unknown>, Type = MockFunctionMetadataType> = { | ||
ref?: number; | ||
members?: Record<string, MockFunctionMetadata<T, Y>>; | ||
mockImpl?: (...args: Y) => T; | ||
name?: string; | ||
refID?: number; | ||
type?: Type; | ||
value?: T; | ||
length?: number; | ||
}; | ||
export interface Mock<T, Y extends Array<unknown> = Array<unknown>> extends Function, MockInstance<T, Y> { | ||
new (...args: Y): T; | ||
(...args: Y): T; | ||
} | ||
export interface SpyInstance<T, Y extends Array<unknown>> extends MockInstance<T, Y> { | ||
} | ||
export interface MockInstance<T, Y extends Array<unknown>> { | ||
_isMockFunction: true; | ||
_protoImpl: Function; | ||
getMockName(): string; | ||
getMockImplementation(): Function | undefined; | ||
mock: MockFunctionState<T, Y>; | ||
mockClear(): this; | ||
mockReset(): this; | ||
mockRestore(): void; | ||
mockImplementation(fn: (...args: Y) => T): this; | ||
mockImplementation(fn: () => Promise<T>): this; | ||
mockImplementationOnce(fn: (...args: Y) => T): this; | ||
mockImplementationOnce(fn: () => Promise<T>): this; | ||
mockName(name: string): this; | ||
mockReturnThis(): this; | ||
mockReturnValue(value: T): this; | ||
mockReturnValueOnce(value: T): this; | ||
mockResolvedValue(value: Unpromisify<T>): this; | ||
mockResolvedValueOnce(value: Unpromisify<T>): this; | ||
mockRejectedValue(value: unknown): this; | ||
mockRejectedValueOnce(value: unknown): this; | ||
} | ||
declare type Unpromisify<T> = T extends Promise<infer R> ? R : never; | ||
@@ -91,3 +88,3 @@ /** | ||
}[keyof T] & string; | ||
declare class ModuleMockerClass { | ||
export declare class ModuleMocker { | ||
private _environmentGlobal; | ||
@@ -98,3 +95,2 @@ private _mockState; | ||
private _invocationCallCounter; | ||
ModuleMocker: typeof ModuleMockerClass; | ||
/** | ||
@@ -119,3 +115,3 @@ * @see README.md | ||
*/ | ||
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: JestMock.MockFunctionMetadata<T, Y>): JestMock.Mock<T, Y>; | ||
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: MockFunctionMetadata<T, Y>): Mock<T, Y>; | ||
/** | ||
@@ -125,8 +121,8 @@ * @see README.md | ||
*/ | ||
getMetadata<T, Y extends Array<unknown>>(component: T, _refs?: Map<T, number>): JestMock.MockFunctionMetadata<T, Y> | null; | ||
isMockFunction<T>(fn: any): fn is JestMock.Mock<T>; | ||
fn<T, Y extends Array<unknown>>(implementation?: (...args: Y) => T): JestMock.Mock<T, Y>; | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): JestMock.SpyInstance<T[M], []>; | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'set'): JestMock.SpyInstance<void, [T[M]]>; | ||
spyOn<T extends {}, M extends FunctionPropertyNames<T>>(object: T, methodName: M): T[M] extends (...args: Array<any>) => any ? JestMock.SpyInstance<ReturnType<T[M]>, Parameters<T[M]>> : never; | ||
getMetadata<T, Y extends Array<unknown>>(component: T, _refs?: Map<T, number>): MockFunctionMetadata<T, Y> | null; | ||
isMockFunction<T>(fn: unknown): fn is Mock<T>; | ||
fn<T, Y extends Array<unknown>>(implementation?: (...args: Y) => T): Mock<T, Y>; | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): SpyInstance<T[M], []>; | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'set'): SpyInstance<void, [T[M]]>; | ||
spyOn<T extends {}, M extends FunctionPropertyNames<T>>(object: T, methodName: M): T[M] extends (...args: Array<any>) => any ? SpyInstance<ReturnType<T[M]>, Parameters<T[M]>> : never; | ||
private _spyOnProperty; | ||
@@ -138,3 +134,8 @@ clearAllMocks(): void; | ||
} | ||
declare const JestMock: ModuleMockerClass; | ||
export = JestMock; | ||
export declare const fn: <T, Y extends unknown[]>(implementation?: ((...args: Y) => T) | undefined) => Mock<T, Y>; | ||
export declare const spyOn: { | ||
<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): SpyInstance<T[M], []>; | ||
<T_2 extends {}, M_2 extends NonFunctionPropertyNames<T_2>>(object: T_2, methodName: M_2, accessType: 'set'): SpyInstance<void, [T_2[M_2]]>; | ||
<T_4 extends {}, M_4 extends FunctionPropertyNames<T_4>>(object: T_4, methodName: M_4): T_4[M_4] extends (...args: Array<any>) => any ? SpyInstance<ReturnType<T_4[M_4]>, Parameters<T_4[M_4]>> : never; | ||
}; | ||
export {}; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.spyOn = exports.fn = exports.ModuleMocker = void 0; | ||
function _defineProperty(obj, key, value) { | ||
@@ -244,3 +249,3 @@ if (key in obj) { | ||
class ModuleMockerClass { | ||
class ModuleMocker { | ||
/** | ||
@@ -262,4 +267,2 @@ * @see README.md | ||
_defineProperty(this, 'ModuleMocker', void 0); | ||
this._environmentGlobal = global; | ||
@@ -269,3 +272,2 @@ this._mockState = new WeakMap(); | ||
this._spyState = new Set(); | ||
this.ModuleMocker = ModuleMockerClass; | ||
this._invocationCallCounter = 1; | ||
@@ -780,2 +782,3 @@ } | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
spyOn(object, methodName, accessType) { | ||
@@ -948,3 +951,7 @@ if (accessType) { | ||
const JestMock = new ModuleMockerClass(global); | ||
module.exports = JestMock; | ||
exports.ModuleMocker = ModuleMocker; | ||
const JestMock = new ModuleMocker(global); | ||
const fn = JestMock.fn; | ||
exports.fn = fn; | ||
const spyOn = JestMock.spyOn; | ||
exports.spyOn = spyOn; |
{ | ||
"name": "jest-mock", | ||
"version": "26.6.2", | ||
"version": "27.0.0-next.0", | ||
"repository": { | ||
@@ -10,15 +10,19 @@ "type": "git", | ||
"engines": { | ||
"node": ">= 10.14.2" | ||
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" | ||
}, | ||
"dependencies": { | ||
"@jest/types": "^26.6.2", | ||
"@jest/types": "^27.0.0-next.0", | ||
"@types/node": "*" | ||
}, | ||
"license": "MIT", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"main": "./build/index.js", | ||
"types": "./build/index.d.ts", | ||
"exports": { | ||
".": "./build/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "4c46930615602cbf983fb7e8e82884c282a624d5" | ||
"gitHead": "4f77c70602cab8419794f10fa39510f13baafef8" | ||
} |
@@ -5,2 +5,6 @@ # jest-mock | ||
```js | ||
import {ModuleMocker} from 'jest-mock'; | ||
``` | ||
### `constructor(global)` | ||
@@ -7,0 +11,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36077
910
93
2
+ Added@jest/types@27.5.1(transitive)
+ Added@types/yargs@16.0.9(transitive)
- Removed@jest/types@26.6.2(transitive)
- Removed@types/yargs@15.0.19(transitive)
Updated@jest/types@^27.0.0-next.0