spy4js
Advanced tools
Comparing version 3.3.1 to 3.3.2
@@ -25,2 +25,17 @@ 'use strict'; | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const IGNORE = Symbol.for('__Spy_IGNORE__'); | ||
@@ -123,3 +138,3 @@ const serialize = serializeAsCode.Serializer.create(o => o === IGNORE && '>IGNORED<' || undefined); | ||
if (useOwnEquals && a.equals instanceof Function) { | ||
if (useOwnEquals && 'equals' in a && typeof a.equals === 'function') { | ||
if (a.equals(b)) { | ||
@@ -337,4 +352,8 @@ return undefined; | ||
mockInfo.active = true; | ||
if (callsFactory) spy.calls(callsFactory(method)); | ||
if (callsFactory) { | ||
spy.calls(callsFactory(method)); | ||
spy.displayName = method; | ||
} | ||
spy[Symbols.onRestore] = () => { | ||
@@ -465,10 +484,20 @@ mockInfo.active = false; | ||
const createGenericComponent = method => props => ({ | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'samp', | ||
props: _extends({ | ||
'data-component': method | ||
}, props), | ||
ref: null | ||
}); | ||
const _excluded = ["children"]; | ||
const createGenericComponent = method => props => { | ||
const { | ||
children | ||
} = props; | ||
_objectWithoutPropertiesLoose(props, _excluded); | ||
const dataProps = {}; | ||
return { | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'samp', | ||
props: _extends({ | ||
'data-component': method, | ||
children | ||
}, dataProps), | ||
ref: null | ||
}; | ||
}; | ||
const createMinimalComponent = () => () => null; | ||
@@ -475,0 +504,0 @@ |
@@ -21,2 +21,17 @@ import { Serializer } from 'serialize-as-code'; | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const IGNORE = Symbol.for('__Spy_IGNORE__'); | ||
@@ -119,3 +134,3 @@ const serialize = Serializer.create(o => o === IGNORE && '>IGNORED<' || undefined); | ||
if (useOwnEquals && a.equals instanceof Function) { | ||
if (useOwnEquals && 'equals' in a && typeof a.equals === 'function') { | ||
if (a.equals(b)) { | ||
@@ -333,4 +348,8 @@ return undefined; | ||
mockInfo.active = true; | ||
if (callsFactory) spy.calls(callsFactory(method)); | ||
if (callsFactory) { | ||
spy.calls(callsFactory(method)); | ||
spy.displayName = method; | ||
} | ||
spy[Symbols.onRestore] = () => { | ||
@@ -461,10 +480,20 @@ mockInfo.active = false; | ||
const createGenericComponent = method => props => ({ | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'samp', | ||
props: _extends({ | ||
'data-component': method | ||
}, props), | ||
ref: null | ||
}); | ||
const _excluded = ["children"]; | ||
const createGenericComponent = method => props => { | ||
const { | ||
children | ||
} = props; | ||
_objectWithoutPropertiesLoose(props, _excluded); | ||
const dataProps = {}; | ||
return { | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'samp', | ||
props: _extends({ | ||
'data-component': method, | ||
children | ||
}, dataProps), | ||
ref: null | ||
}; | ||
}; | ||
const createMinimalComponent = () => () => null; | ||
@@ -471,0 +500,0 @@ |
{ | ||
"name": "spy4js", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "Smart, compact and powerful spy test framework", | ||
@@ -28,29 +28,29 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"serialize-as-code": "^2.0.1" | ||
"serialize-as-code": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.16.0", | ||
"@babel/eslint-parser": "^7.16.3", | ||
"@babel/plugin-proposal-class-properties": "^7.16.0", | ||
"@babel/preset-env": "^7.16.4", | ||
"@babel/preset-react": "^7.16.0", | ||
"@babel/preset-typescript": "^7.16.0", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-node-resolve": "^13.0.6", | ||
"@babel/core": "^7.17.8", | ||
"@babel/eslint-parser": "^7.17.0", | ||
"@babel/plugin-proposal-class-properties": "^7.16.7", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-react": "^7.16.7", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@sucrase/jest-plugin": "^2.2.0", | ||
"@testing-library/react": "^12.1.2", | ||
"@types/jest": "^27.0.3", | ||
"@types/react": "^17.0.37", | ||
"@typescript-eslint/eslint-plugin": "^5.4.0", | ||
"@typescript-eslint/parser": "^5.4.0", | ||
"@testing-library/react": "^13.0.0-alpha.6", | ||
"@types/jest": "^27.4.1", | ||
"@types/react": "^17.0.43", | ||
"@typescript-eslint/eslint-plugin": "^5.17.0", | ||
"@typescript-eslint/parser": "^5.17.0", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.3.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint": "^8.12.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"rollup": "^2.60.1", | ||
"typescript": "^4.5.2" | ||
"jest": "^27.5.1", | ||
"prettier": "^2.6.1", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0", | ||
"rollup": "^2.70.1", | ||
"typescript": "^4.6.3" | ||
}, | ||
@@ -57,0 +57,0 @@ "scripts": { |
@@ -71,3 +71,6 @@ /** | ||
mockInfo.active = true; | ||
if (callsFactory) spy.calls(callsFactory(method)); | ||
if (callsFactory) { | ||
spy.calls(callsFactory(method)); | ||
spy.displayName = method; // TODO: test if name works, too | ||
} | ||
spy[Symbols.onRestore] = () => { | ||
@@ -74,0 +77,0 @@ mockInfo.active = false; |
@@ -1,8 +0,19 @@ | ||
export const createGenericComponent = (method: string) => (props: any) => ({ | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'samp', | ||
props: { 'data-component': method, ...props }, | ||
ref: null, | ||
}); | ||
import { serialize } from './serializer'; | ||
// can be computational expensive and cause some issue if serialization would fail | ||
// maybe we allow to configure it after some time, as it might be very useful | ||
export const _GenericComponent = { serializeAllProps: false }; | ||
export const createGenericComponent = (method: string) => (props: any) => { | ||
const { children, ...rest } = props; | ||
const dataProps = _GenericComponent.serializeAllProps | ||
? Object.fromEntries(Object.entries(rest).map(([name, v]) => ['data-prop-' + name.toLowerCase(), serialize(v)])) | ||
: {}; | ||
return { | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'samp', | ||
props: { 'data-component': method, children, ...dataProps }, | ||
ref: null, | ||
}; | ||
}; | ||
export const createMinimalComponent = () => () => null; |
@@ -116,3 +116,3 @@ /** | ||
} | ||
if (useOwnEquals && a.equals instanceof Function) { | ||
if (useOwnEquals && 'equals' in a && typeof a.equals === 'function') { | ||
if (a.equals(b)) { | ||
@@ -119,0 +119,0 @@ return undefined; |
161052
2930
Updatedserialize-as-code@^2.0.2