Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-mock

Package Overview
Dependencies
Maintainers
7
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-mock - npm Package Compare versions

Comparing version 26.0.1 to 26.1.0

68

build/index.d.ts

@@ -22,2 +22,30 @@ /**

};
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: T): this;
mockResolvedValueOnce(value: T): this;
mockRejectedValue(value: T): this;
mockRejectedValueOnce(value: T): this;
}
}

@@ -62,30 +90,2 @@ /**

}[keyof T] & string;
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: T): this;
mockResolvedValueOnce(value: T): this;
mockRejectedValue(value: T): this;
mockRejectedValueOnce(value: T): this;
}
declare class ModuleMockerClass {

@@ -117,3 +117,3 @@ private _environmentGlobal;

*/
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: JestMock.MockFunctionMetadata<T, Y>): Mock<T, Y>;
generateFromMetadata<T, Y extends Array<unknown>>(_metadata: JestMock.MockFunctionMetadata<T, Y>): JestMock.Mock<T, Y>;
/**

@@ -124,7 +124,7 @@ * @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 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;
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;
private _spyOnProperty;

@@ -131,0 +131,0 @@ clearAllMocks(): void;

@@ -299,3 +299,3 @@ 'use strict';

if (!isReadonlyProp(object, prop)) {
const propDesc = Object.getOwnPropertyDescriptor(object, prop); // @ts-ignore Object.__esModule
const propDesc = Object.getOwnPropertyDescriptor(object, prop);

@@ -419,6 +419,6 @@ if ((propDesc !== undefined && !propDesc.get) || object.__esModule) {

if (prototype[slot].type === 'function') {
// @ts-ignore no index signature
const protoImpl = this[slot]; // @ts-ignore no index signature
// @ts-expect-error no index signature
const protoImpl = this[slot]; // @ts-expect-error no index signature
this[slot] = mocker.generateFromMetadata(prototype[slot]); // @ts-ignore no index signature
this[slot] = mocker.generateFromMetadata(prototype[slot]); // @ts-expect-error no index signature

@@ -634,3 +634,3 @@ this[slot]._protoImpl = protoImpl;

// overloading of _makeComponent and not _generateMock?
// @ts-ignore
// @ts-expect-error
const mock = this._makeComponent(metadata);

@@ -716,7 +716,7 @@

} else if (type === 'function') {
// @ts-ignore this is a function so it has a name
metadata.name = component.name; // @ts-ignore may be a mock
// @ts-expect-error this is a function so it has a name
metadata.name = component.name; // @ts-expect-error may be a mock
if (component._isMockFunction === true) {
// @ts-ignore may be a mock
// @ts-expect-error may be a mock
metadata.mockImpl = component.getMockImplementation();

@@ -733,3 +733,3 @@ }

if (
type === 'function' && // @ts-ignore may be a mock
type === 'function' && // @ts-expect-error may be a mock
component._isMockFunction === true &&

@@ -739,3 +739,3 @@ slot.match(/^mock/)

return;
} // @ts-ignore no index signature
} // @ts-expect-error no index signature

@@ -804,3 +804,3 @@ const slotMetadata = this.getMetadata(component[slot], refs);

const isMethodOwner = object.hasOwnProperty(methodName); // @ts-ignore overriding original method with a Mock
const isMethodOwner = object.hasOwnProperty(methodName); // @ts-expect-error overriding original method with a Mock

@@ -818,3 +818,3 @@ object[methodName] = this._makeComponent(

}
); // @ts-ignore original method is now a Mock
); // @ts-expect-error original method is now a Mock

@@ -879,3 +879,3 @@ object[methodName].mockImplementation(function () {

);
} // @ts-ignore: mock is assignable
} // @ts-expect-error: mock is assignable

@@ -887,3 +887,3 @@ descriptor[accessType] = this._makeComponent(

() => {
// @ts-ignore: mock is assignable
// @ts-expect-error: mock is assignable
descriptor[accessType] = original;

@@ -894,3 +894,3 @@ Object.defineProperty(obj, propertyName, descriptor);

descriptor[accessType].mockImplementation(function () {
// @ts-ignore
// @ts-expect-error
return original.apply(this, arguments);

@@ -897,0 +897,0 @@ });

{
"name": "jest-mock",
"version": "26.0.1",
"version": "26.1.0",
"repository": {

@@ -13,3 +13,3 @@ "type": "git",

"dependencies": {
"@jest/types": "^26.0.1"
"@jest/types": "^26.1.0"
},

@@ -25,3 +25,3 @@ "devDependencies": {

},
"gitHead": "40b8e1e157c9981dda5a68d73fff647e80fc9f5c"
"gitHead": "817d8b6aca845dd4fcfd7f8316293e69f3a116c5"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc