Socket
Socket
Sign inDemoInstall

spy4js

Package Overview
Dependencies
1
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0-beta.1 to 4.0.0-beta.2

23

dist/cjs/index.js

@@ -50,3 +50,2 @@ 'use strict';

const COMPARE = comparator => new SpyComparator(comparator);
const MAPPER = (from, to) => new SpyComparator(mapper => {

@@ -58,3 +57,2 @@ const result = mapper(...(Array.isArray(from) ? from : [from]));

const __different = type => ['different ' + type];
const __diff = (a, b, useOwnEquals, alreadyComparedArray = []) => {

@@ -138,3 +136,2 @@ if (a === IGNORE || b === IGNORE) return undefined;

};
const differenceOf = (a, b, config = {

@@ -184,3 +181,3 @@ useOwnEquals: true

var _obj$methodName, _obj$methodName$Symbo;
(_obj$methodName = obj[methodName]) == null ? void 0 : (_obj$methodName$Symbo = _obj$methodName[Symbols.onRestore]) == null ? void 0 : _obj$methodName$Symbo.call(_obj$methodName);
(_obj$methodName = obj[methodName]) == null || (_obj$methodName$Symbo = _obj$methodName[Symbols.onRestore]) == null || _obj$methodName$Symbo.call(_obj$methodName);
obj[methodName] = method;

@@ -198,3 +195,2 @@ }

}
restoreAll() {

@@ -206,3 +202,2 @@ Object.values(this.register).forEach(entry => {

}
restore(index) {

@@ -215,3 +210,2 @@ const entry = this.register[index];

}
push(obj, methodName) {

@@ -226,3 +220,2 @@ this.registerCount += 1;

}
getOriginalMethod(index) {

@@ -234,3 +227,2 @@ const entry = this.register[index];

}
persist(index, intoPersReg) {

@@ -315,3 +307,2 @@ const fromReg = intoPersReg ? this.register : this.persReg;

}
spy[Symbols.onRestore] = () => {

@@ -363,3 +354,2 @@ mockInfo.activeMethods.delete(method);

};
const registry = new SpyRegistry();

@@ -613,13 +603,7 @@ let __LOCK__ = true;

};
const Spy = name => _createSpy(name);
Spy.configure = configure;
Spy.IGNORE = IGNORE;
Spy.COMPARE = COMPARE;
Spy.MAPPER = MAPPER;
Spy.on = (obj, methodName) => {

@@ -642,11 +626,7 @@ const method = obj[methodName];

};
Spy.mock = (obj, ...methodNames) => createMock(obj, methodNames, Spy.on);
Spy.mockReactComponents = (obj, ...methodNames) => createMock(obj, methodNames, Spy.on, Config.useGenericReactMocks ? createGenericComponent : createMinimalComponent);
Spy.restoreAll = () => {
registry.restoreAll();
};
Spy.resetAll = () => {

@@ -679,3 +659,2 @@ AllCreatedSpies.forEach(spy => spy.reset());

});
expect.addSnapshotSerializer({

@@ -682,0 +661,0 @@ test: v => v && v[Symbols.isSpy],

@@ -48,3 +48,2 @@ import { Serializer } from 'serialize-as-code';

const COMPARE = comparator => new SpyComparator(comparator);
const MAPPER = (from, to) => new SpyComparator(mapper => {

@@ -56,3 +55,2 @@ const result = mapper(...(Array.isArray(from) ? from : [from]));

const __different = type => ['different ' + type];
const __diff = (a, b, useOwnEquals, alreadyComparedArray = []) => {

@@ -136,3 +134,2 @@ if (a === IGNORE || b === IGNORE) return undefined;

};
const differenceOf = (a, b, config = {

@@ -182,3 +179,3 @@ useOwnEquals: true

var _obj$methodName, _obj$methodName$Symbo;
(_obj$methodName = obj[methodName]) == null ? void 0 : (_obj$methodName$Symbo = _obj$methodName[Symbols.onRestore]) == null ? void 0 : _obj$methodName$Symbo.call(_obj$methodName);
(_obj$methodName = obj[methodName]) == null || (_obj$methodName$Symbo = _obj$methodName[Symbols.onRestore]) == null || _obj$methodName$Symbo.call(_obj$methodName);
obj[methodName] = method;

@@ -196,3 +193,2 @@ }

}
restoreAll() {

@@ -204,3 +200,2 @@ Object.values(this.register).forEach(entry => {

}
restore(index) {

@@ -213,3 +208,2 @@ const entry = this.register[index];

}
push(obj, methodName) {

@@ -224,3 +218,2 @@ this.registerCount += 1;

}
getOriginalMethod(index) {

@@ -232,3 +225,2 @@ const entry = this.register[index];

}
persist(index, intoPersReg) {

@@ -313,3 +305,2 @@ const fromReg = intoPersReg ? this.register : this.persReg;

}
spy[Symbols.onRestore] = () => {

@@ -361,3 +352,2 @@ mockInfo.activeMethods.delete(method);

};
const registry = new SpyRegistry();

@@ -611,13 +601,7 @@ let __LOCK__ = true;

};
const Spy = name => _createSpy(name);
Spy.configure = configure;
Spy.IGNORE = IGNORE;
Spy.COMPARE = COMPARE;
Spy.MAPPER = MAPPER;
Spy.on = (obj, methodName) => {

@@ -640,11 +624,7 @@ const method = obj[methodName];

};
Spy.mock = (obj, ...methodNames) => createMock(obj, methodNames, Spy.on);
Spy.mockReactComponents = (obj, ...methodNames) => createMock(obj, methodNames, Spy.on, Config.useGenericReactMocks ? createGenericComponent : createMinimalComponent);
Spy.restoreAll = () => {
registry.restoreAll();
};
Spy.resetAll = () => {

@@ -677,3 +657,2 @@ AllCreatedSpies.forEach(spy => spy.reset());

});
expect.addSnapshotSerializer({

@@ -680,0 +659,0 @@ test: v => v && v[Symbols.isSpy],

4

dist/types/config.d.ts

@@ -1,2 +0,2 @@

declare type SpyNonSetupConfig = {
type SpyNonSetupConfig = {
useOwnEquals: boolean;

@@ -7,3 +7,3 @@ enforceOrder: boolean;

};
export declare type SpyConfig = SpyNonSetupConfig & {
export type SpyConfig = SpyNonSetupConfig & {
afterEach?: (cb: () => void) => void;

@@ -10,0 +10,0 @@ beforeEach?: (cb: () => void) => void;

@@ -1,5 +0,5 @@

export declare type Mockable = Record<string, any>;
declare type SpyOn = (obj: Mockable, method: keyof typeof obj) => any;
export type Mockable = Record<string, any>;
type SpyOn = (obj: Mockable, method: keyof typeof obj) => any;
export declare const createMock: <T extends Mockable, K extends keyof T>(obj: T, methods: K[], spyOn: SpyOn, callsFactory?: MockInfo['callsFactory']) => { [P in K]: any; };
declare type MockInfo = {
type MockInfo = {
mock: Mockable;

@@ -6,0 +6,0 @@ mocked: Mockable;

@@ -1,2 +0,2 @@

declare type SpyRegister = {
type SpyRegister = {
[index: number]: {

@@ -3,0 +3,0 @@ obj: any;

@@ -11,19 +11,19 @@ /**

import { configure, configureAll } from './config';
declare type SpyConfig = {
type SpyInstanceConfig = {
useOwnEquals: boolean;
persistent: boolean;
};
export declare type SpyInstance = {
(...args: any[]): any;
configure: (config: Partial<SpyConfig>) => SpyInstance;
calls: (...funcs: Function[]) => SpyInstance;
returns: (...args: any[]) => SpyInstance;
resolves: (...args: any[]) => SpyInstance;
rejects: (...msgOrErrors: OptionalMessageOrError[]) => SpyInstance;
throws: (msgOrError?: MessageOrError) => SpyInstance;
reset: () => SpyInstance;
restore: () => SpyInstance;
transparent: () => SpyInstance;
transparentAfter: (callCount: number) => SpyInstance;
addSnapshotSerializer: (serialize: string | ((...args: any[]) => string)) => SpyInstance;
type FlatAwaited<TVal> = TVal extends PromiseLike<infer TAwaited> ? TAwaited : never;
export type SpyInstance<TFunc extends (...args: any) => any = (...args: any) => any> = TFunc & {
configure: (config: Partial<SpyInstanceConfig>) => SpyInstance<TFunc>;
calls: (...funcs: TFunc[]) => SpyInstance<TFunc>;
returns: (...args: ReturnType<TFunc>[]) => SpyInstance<TFunc>;
resolves: FlatAwaited<ReturnType<TFunc>> extends never ? never : (...args: FlatAwaited<ReturnType<TFunc>>[]) => SpyInstance<TFunc>;
rejects: FlatAwaited<ReturnType<TFunc>> extends never ? never : (...msgOrErrors: OptionalMessageOrError[]) => SpyInstance<TFunc>;
throws: (msgOrError?: MessageOrError) => SpyInstance<TFunc>;
reset: () => SpyInstance<TFunc>;
restore: () => SpyInstance<TFunc>;
transparent: () => SpyInstance<TFunc>;
transparentAfter: (callCount: number) => SpyInstance<TFunc>;
addSnapshotSerializer: (serialize: string | ((...args: any[]) => string)) => SpyInstance<TFunc>;
wasCalled: (callCount?: number) => void;

@@ -52,6 +52,6 @@ hasCallHistory: (...callHistory: Array<any[] | any>) => void;

[Symbols.func]: Function;
[Symbols.config]: SpyConfig;
[Symbols.config]: SpyInstanceConfig;
[Symbols.onRestore]?: () => void;
};
declare type ISpy = {
type ISpy = {
(name?: string): SpyInstance;

@@ -63,8 +63,8 @@ configure: typeof configure;

MAPPER: typeof MAPPER;
on<T extends Mockable, K extends keyof T>(obj: T, methodName: K): SpyInstance;
on<T extends Mockable, K extends keyof T>(obj: T, methodName: K): SpyInstance<T[K]>;
mock<T extends Mockable, K extends keyof T>(obj: T, ...methodNames: K[]): {
[P in K]: SpyInstance;
[P in K]: SpyInstance<T[P]>;
};
mockReactComponents<T extends Mockable, K extends keyof T>(obj: T, ...methodNames: K[]): {
[P in K]: SpyInstance;
[P in K]: SpyInstance<T[P]>;
};

@@ -71,0 +71,0 @@ restoreAll(): void;

@@ -7,3 +7,3 @@ /**

*/
declare type Comparator = (arg: any) => boolean | void;
type Comparator = (arg: any) => boolean | void;
/**

@@ -58,5 +58,5 @@ * This function may create individual comparators

}) => string | undefined;
export declare type MessageOrError = string | Error;
export declare type OptionalMessageOrError = MessageOrError | undefined;
export type MessageOrError = string | Error;
export type OptionalMessageOrError = MessageOrError | undefined;
declare const toError: (msgOrError: OptionalMessageOrError, spyName: string) => Error;
export { differenceOf, COMPARE, toError, MAPPER };
{
"name": "spy4js",
"version": "4.0.0-beta.1",
"version": "4.0.0-beta.2",
"description": "Smart, compact and powerful spy test framework",

@@ -28,27 +28,29 @@ "main": "dist/cjs/index.js",

"devDependencies": {
"@babel/core": "^7.20.2",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-babel": "^6.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-typescript": "^7.23.3",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@sucrase/jest-plugin": "^3.0.0",
"@testing-library/react": "^13.4.0",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.0",
"@types/react": "^18.2.47",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^1.1.3",
"coveralls": "^3.1.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"prettier": "^2.7.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^3.3.0",
"sucrase": "^3.28.0",
"typescript": "^4.8.4",
"vitest": "^0.29.3"
"rollup": "^4.9.4",
"sucrase": "^3.35.0",
"typescript": "^5.3.3",
"vitest": "^1.1.3"
},

@@ -60,5 +62,6 @@ "scripts": {

"lint:ts": "tsc",
"test": "pnpm test:jest && pnpm test:vi",
"test:jest": "jest --all --coverage --color",
"test:vi": "vitest run",
"test": "pnpm test:jest && pnpm test:vi && pnpm test:bun",
"test:jest": "jest --all --color",
"test:vi": "vitest run --coverage",
"test:bun": "bun test",
"test:update": "jest -u",

@@ -65,0 +68,0 @@ "coveralls": "cat ./coverage/lcov.info | coveralls"

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc