enzyme-theme-utils
Advanced tools
Comparing version 2.0.2 to 3.0.0
@@ -11,83 +11,79 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return target; | ||
}; | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
}; | ||
} | ||
function shallowWithTheme(children) { | ||
function shallowWithTheme(tree) { | ||
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// shallow mount the component wrapped in a ThemeProvider | ||
var wrapper = enzyme.shallow(React.createElement( | ||
styledComponents.ThemeProvider, | ||
{ theme: theme }, | ||
children | ||
), options); | ||
// Set the context and remount. | ||
var themeProvider = wrapper.shallow({ | ||
context: wrapper.instance().getChildContext() | ||
}); | ||
var WrappingThemeProvider = function WrappingThemeProvider(props) { | ||
return React.createElement(styledComponents.ThemeProvider, { | ||
theme: theme | ||
}, props.children); | ||
}; | ||
// shallow mount the child component with the context | ||
return enzyme.shallow(themeProvider.instance().props.children, { context: wrapper.instance().getChildContext(), childContextTypes: styledComponents.ThemeProvider.childContextTypes }); | ||
return enzyme.shallow(tree, _objectSpread2({ | ||
wrappingComponent: WrappingThemeProvider | ||
}, options)); | ||
} | ||
function mountWithTheme(children) { | ||
function mountWithTheme(tree) { | ||
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Moun the component wrapped in a ThemeProvider | ||
var wrapper = enzyme.mount(React.createElement( | ||
styledComponents.ThemeProvider, | ||
{ theme: theme }, | ||
children | ||
), options); | ||
// Set the context and remount. | ||
var themeProvider = wrapper.mount({ | ||
context: wrapper.instance().getChildContext() | ||
}); | ||
var WrappingThemeProvider = function WrappingThemeProvider(props) { | ||
return React.createElement(styledComponents.ThemeProvider, { | ||
theme: theme | ||
}, props.children); | ||
}; // Mount the child component with the context | ||
var context = options.context, | ||
childContextTypes = options.childContextTypes, | ||
rest = objectWithoutProperties(options, ['context', 'childContextTypes']); | ||
var contextObj = _extends({}, wrapper.instance().getChildContext(), context); | ||
var childContextTypesObj = _extends({}, styledComponents.ThemeProvider.childContextTypes, childContextTypes); | ||
// console.log(contextObj, childContextTypes) | ||
// Mount the child component with the context | ||
return enzyme.mount(themeProvider.instance().props.children, _extends({ context: contextObj, childContextTypes: childContextTypesObj }, rest)); | ||
return enzyme.mount(tree, _objectSpread2({ | ||
wrappingComponent: WrappingThemeProvider | ||
}, options)); | ||
} | ||
@@ -94,0 +90,0 @@ |
{ | ||
"name": "enzyme-theme-utils", | ||
"main": "dist/enzyme-theme-utils.js", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Enzyme Theme Utilities", | ||
@@ -17,26 +17,22 @@ "scripts": { | ||
"license": "MIT", | ||
"babel": { | ||
"presets": [ | ||
"env", | ||
"stage-0", | ||
"react" | ||
] | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.3", | ||
"babel-jest": "^22.4.3", | ||
"@babel/core": "^7.5.5", | ||
"@babel/plugin-proposal-class-properties": "^7.5.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.5.5", | ||
"@babel/preset-env": "^7.4.4", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-eslint": "^9.0.0", | ||
"babel-jest": "^24.7.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"enzyme": "^3.1.0", | ||
"enzyme-adapter-react-16": "^1.1.1", | ||
"jest": "^22.4.3", | ||
"jest-styled-components": "^4.4.0", | ||
"enzyme": "^3.10.0", | ||
"enzyme-adapter-react-16": "^1.14.0", | ||
"jest": "^24.9.0", | ||
"jest-styled-components": "^6.3.3", | ||
"prop-types": "^15.6.1", | ||
"react": "16.4.0", | ||
"react-dom": "16.4.0", | ||
"react": "16.8.0", | ||
"react-dom": "16.8.0", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.45.2", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-includepaths": "^0.2.2", | ||
@@ -47,6 +43,6 @@ "rollup-plugin-node-resolve": "^3.0.0", | ||
"peerDependencies": { | ||
"styled-components": ">=2.0.0 || <= 4.0.0", | ||
"react": ">=15.2.0 || <= 16.4.0", | ||
"enzyme": ">=3.1.0" | ||
"styled-components": ">= 3.4.2", | ||
"react": ">= 16.5.0", | ||
"enzyme": ">=3.10.0" | ||
} | ||
} |
@@ -11,5 +11,10 @@ // import resolve from 'rollup-plugin-node-resolve' | ||
babel({ | ||
'presets': [['es2015', {'modules': false}], 'stage-0', 'react'], | ||
'plugins': ['external-helpers'], | ||
'exclude': 'node_modules/**' | ||
presets: [ | ||
'@babel/preset-env', | ||
'@babel/preset-react' | ||
], | ||
plugins: [ | ||
'@babel/plugin-proposal-object-rest-spread', | ||
'@babel/plugin-proposal-class-properties' | ||
] | ||
}), | ||
@@ -16,0 +21,0 @@ includePaths({ |
Sorry, the diff of this file is not supported yet
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
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
135
14042
22
8