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

jest-mock

Package Overview
Dependencies
Maintainers
5
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 22.2.0 to 22.4.3

232

build/index.js
'use strict';
const MOCK_CONSTRUCTOR_NAME = 'mockConstructor'; /**

@@ -46,3 +10,7 @@ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

*
*/const FUNCTION_NAME_RESERVED_PATTERN = /[\s!-\/:-@\[-`{-~]/;const FUNCTION_NAME_RESERVED_REPLACE = new RegExp(FUNCTION_NAME_RESERVED_PATTERN.source, 'g');
*/
const FUNCTION_NAME_RESERVED_PATTERN = /[\s!-\/:-@\[-`{-~]/;
const FUNCTION_NAME_RESERVED_REPLACE = new RegExp(FUNCTION_NAME_RESERVED_PATTERN.source, 'g');
const RESERVED_KEYWORDS = Object.assign(Object.create(null), {

@@ -96,5 +64,5 @@ arguments: true,

with: true,
yield: true });
yield: true
});
function matchArity(fn, length) {

@@ -153,5 +121,5 @@ let mockConstructor;

};
break;}
break;
}
return mockConstructor;

@@ -171,8 +139,3 @@ }

return 'object';
} else if (
isA('Number', ref) ||
isA('String', ref) ||
isA('Boolean', ref) ||
isA('Symbol', ref))
{
} else if (isA('Number', ref) || isA('String', ref) || isA('Boolean', ref) || isA('Symbol', ref)) {
return 'constant';

@@ -193,15 +156,3 @@ } else if (isA('Map', ref) || isA('WeakMap', ref) || isA('Set', ref)) {

function isReadonlyProp(object, prop) {
return (
(prop === 'arguments' ||
prop === 'caller' ||
prop === 'callee' ||
prop === 'name' ||
prop === 'length') && (
isA('Function', object) || isA('AsyncFunction', object)) ||
(prop === 'source' ||
prop === 'global' ||
prop === 'ignoreCase' ||
prop === 'multiline') &&
isA('RegExp', object));
return (prop === 'arguments' || prop === 'caller' || prop === 'callee' || prop === 'name' || prop === 'length') && (isA('Function', object) || isA('AsyncFunction', object)) || (prop === 'source' || prop === 'global' || prop === 'ignoreCase' || prop === 'multiline') && isA('RegExp', object);
}

@@ -235,6 +186,3 @@

function wrapAsyncParam(
fn,
asyncAction)
{
function wrapAsyncParam(fn, asyncAction) {
if (asyncAction === 'reject') {

@@ -249,12 +197,7 @@ return value => fn(Promise.reject(value));

/**
* @see README.md
* @param global Global object of the test environment, used to create
* mocks
*/
* @see README.md
* @param global Global object of the test environment, used to create
* mocks
*/
constructor(global) {

@@ -293,4 +236,4 @@ this._environmentGlobal = global;

specificMockImpls: [],
specificReturnValues: [] };
specificReturnValues: []
};
}

@@ -302,4 +245,4 @@

instances: [],
timestamps: [] };
timestamps: []
};
}

@@ -314,8 +257,3 @@

return new this._environmentGlobal.RegExp('');
} else if (
metadata.type === 'constant' ||
metadata.type === 'collection' ||
metadata.type === 'null' ||
metadata.type === 'undefined')
{
} else if (metadata.type === 'constant' || metadata.type === 'collection' || metadata.type === 'null' || metadata.type === 'undefined') {
return metadata.value;

@@ -327,7 +265,3 @@ } else if (metadata.type === 'function') {

const prototype =
metadata.members &&
metadata.members.prototype &&
metadata.members.prototype.members ||
{};
const prototype = metadata.members && metadata.members.prototype && metadata.members.prototype.members || {};
const prototypeSlots = getSlots(prototype);

@@ -355,5 +289,3 @@ const mocker = this;

// Run the mock constructor implementation
const mockImpl = mockConfig.specificMockImpls.length ?
mockConfig.specificMockImpls.shift() :
mockConfig.mockImpl;
const mockImpl = mockConfig.specificMockImpls.length ? mockConfig.specificMockImpls.shift() : mockConfig.mockImpl;
return mockImpl && mockImpl.apply(this, arguments);

@@ -412,5 +344,5 @@ }

get: () => this._ensureMockState(f),
set: val => this._mockState.set(f, val) });
set: val => this._mockState.set(f, val)
});
f.mockClear = () => {

@@ -434,7 +366,4 @@ this._mockState.delete(f);

f.mockResolvedValueOnce = wrapAsyncParam(
f.mockReturnValueOnce,
'resolve');
f.mockResolvedValueOnce = wrapAsyncParam(f.mockReturnValueOnce, 'resolve');
f.mockRejectedValueOnce = wrapAsyncParam(f.mockReturnValueOnce, 'reject');

@@ -472,4 +401,3 @@

f.mockReturnThis = () =>
f.mockImplementation(function () {
f.mockReturnThis = () => f.mockImplementation(function () {
return this;

@@ -504,6 +432,3 @@ });

_createMockFunction(
metadata,
mockConstructor)
{
_createMockFunction(metadata, mockConstructor) {
let name = metadata.name;

@@ -544,24 +469,9 @@ if (!name) {

const body =
'return function ' +
name +
'() {' +
'return ' +
MOCK_CONSTRUCTOR_NAME +
'.apply(this,arguments);' +
'}' +
bindCall;
const createConstructor = new this._environmentGlobal.Function(
MOCK_CONSTRUCTOR_NAME,
body);
const body = 'return function ' + name + '() {' + 'return ' + MOCK_CONSTRUCTOR_NAME + '.apply(this,arguments);' + '}' + bindCall;
const createConstructor = new this._environmentGlobal.Function(MOCK_CONSTRUCTOR_NAME, body);
return createConstructor(mockConstructor);
}
_generateMock(
metadata,
callbacks,
refs)
{
_generateMock(metadata, callbacks, refs) {
const mock = this._makeComponent(metadata);

@@ -581,7 +491,3 @@ if (metadata.refID != null) {

if (
metadata.type !== 'undefined' &&
metadata.type !== 'null' &&
mock.prototype)
{
if (metadata.type !== 'undefined' && metadata.type !== 'null' && mock.prototype) {
mock.prototype.constructor = mock;

@@ -594,6 +500,6 @@ }

/**
* @see README.md
* @param metadata Metadata for the mock in the schema returned by the
* getMetadata method of this module.
*/
* @see README.md
* @param metadata Metadata for the mock in the schema returned by the
* getMetadata method of this module.
*/
generateFromMetadata(_metadata) {

@@ -608,5 +514,5 @@ const callbacks = [];

/**
* @see README.md
* @param component The component for which to retrieve metadata.
*/
* @see README.md
* @param component The component for which to retrieve metadata.
*/
getMetadata(component, _refs) {

@@ -625,8 +531,3 @@ const refs = _refs || new Map();

const metadata = { type };
if (
type === 'constant' ||
type === 'collection' ||
type === 'undefined' ||
type === 'null')
{
if (type === 'constant' || type === 'collection' || type === 'undefined' || type === 'null') {
metadata.value = component;

@@ -649,15 +550,7 @@ return metadata;

getSlots(component).forEach(slot => {
if (
type === 'function' &&
component._isMockFunction &&
slot.match(/^mock/))
{
if (type === 'function' && component._isMockFunction && slot.match(/^mock/)) {
return;
}
if (
!component.hasOwnProperty && component[slot] !== undefined ||
component.hasOwnProperty && component.hasOwnProperty(slot) ||
type === 'object' && component[slot] != Object.prototype[slot])
{
if (!component.hasOwnProperty && component[slot] !== undefined || component.hasOwnProperty && component.hasOwnProperty(slot) || type === 'object' && component[slot] != Object.prototype[slot]) {
const slotMetadata = this.getMetadata(component[slot], refs);

@@ -712,5 +605,3 @@ if (slotMetadata) {

if (typeof object !== 'object' && typeof object !== 'function') {
throw new Error(
'Cannot spyOn on a primitive value; ' + this._typeOf(object) + ' given');
throw new Error('Cannot spyOn on a primitive value; ' + this._typeOf(object) + ' given');
}

@@ -722,9 +613,3 @@

if (typeof original !== 'function') {
throw new Error(
'Cannot spy the ' +
methodName +
' property because it is not a function; ' +
this._typeOf(original) +
' given instead');
throw new Error('Cannot spy the ' + methodName + ' property because it is not a function; ' + this._typeOf(original) + ' given instead');
}

@@ -744,13 +629,11 @@

_spyOnProperty(obj, propertyName) {let accessType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'get';
_spyOnProperty(obj, propertyName) {
let accessType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'get';
if (typeof obj !== 'object' && typeof obj !== 'function') {
throw new Error(
'Cannot spyOn on a primitive value; ' + this._typeOf(obj) + ' given');
throw new Error('Cannot spyOn on a primitive value; ' + this._typeOf(obj) + ' given');
}
if (!obj) {
throw new Error(
'spyOn could not find an object to spy upon for ' + propertyName + '');
throw new Error('spyOn could not find an object to spy upon for ' + propertyName + '');
}

@@ -773,5 +656,3 @@

if (!descriptor[accessType]) {
throw new Error(
'Property ' + propertyName + ' does not have access type ' + accessType);
throw new Error('Property ' + propertyName + ' does not have access type ' + accessType);
}

@@ -783,9 +664,3 @@

if (typeof original !== 'function') {
throw new Error(
'Cannot spy the ' +
propertyName +
' property because it is not a function; ' +
this._typeOf(original) +
' given instead');
throw new Error('Cannot spy the ' + propertyName + ' property because it is not a function; ' + this._typeOf(original) + ' given instead');
}

@@ -823,6 +698,5 @@

return value == null ? '' + value : typeof value;
}}
}
}
module.exports = new ModuleMockerClass(global);
{
"name": "jest-mock",
"version": "22.2.0",
"version": "22.4.3",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

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