Socket
Socket
Sign inDemoInstall

enzyme-matchers

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enzyme-matchers - npm Package Compare versions

Comparing version 4.2.0 to 5.0.0

lib/assertions/toBeEmptyRender.js

10

lib/assertions/toBeChecked.js

@@ -34,9 +34,9 @@ 'use strict';

// set to the default checked
if (props.hasOwnProperty('defaultChecked')) {
pass = props.defaultChecked || false;
// Use `defaultChecked` if present.
if (props.hasOwnProperty('defaultChecked') && typeof props.defaultChecked === 'boolean') {
pass = props.defaultChecked;
}
// if it has the checked property, CHECK that.
if (props.hasOwnProperty('checked')) {
// Use `checked` if present, will take precedence over `defaultChecked`.
if (props.hasOwnProperty('checked') && typeof props.checked === 'boolean') {
pass = props.checked;

@@ -43,0 +43,0 @@ }

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

message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> to have className of "' + normalizedClassName + '" but instead found "' + actualClassName + '"', // eslint-disable-line max-len
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> not to contain "' + normalizedClassName + '" for it\'s classname', // eslint-disable-line max-len
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> not to contain "' + normalizedClassName + '" in its className',
contextualInformation: {

@@ -54,0 +54,0 @@ actual: 'Found node output: ' + (0, _html2.default)(enzymeWrapper)

@@ -7,6 +7,10 @@ 'use strict';

var _deepEqualIdent = require('deep-equal-ident');
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule toHavePropAssertion
*
*/
var _deepEqualIdent2 = _interopRequireDefault(_deepEqualIdent);
var _name = require('../utils/name');

@@ -16,2 +20,6 @@

var _reduceAssertionObject = require('../utils/reduceAssertionObject');
var _reduceAssertionObject2 = _interopRequireDefault(_reduceAssertionObject);
var _stringify3 = require('../utils/stringify');

@@ -27,36 +35,36 @@

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 obj; } /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule toHavePropAssertion
*
*/
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 obj; }
function toHaveProp(enzymeWrapper, propKey, propValue) {
var props = enzymeWrapper.props();
var contextualInformation = {
actual: 'Actual: ' + (0, _stringify4.default)(_defineProperty({}, propKey, props[propKey])),
expected: 'Expected: ' + (0, _stringify4.default)(_defineProperty({}, propKey, propValue))
};
var wrapperName = (0, _name2.default)(enzymeWrapper);
// error if the prop doesnt exist
if (!props.hasOwnProperty(propKey)) {
contextualInformation.actual = '';
// The API allows to check if a component has a prop in general by dropping the third
// argument.
if (propValue === undefined && arguments.length === 2 && (typeof propKey === 'undefined' ? 'undefined' : _typeof(propKey)) !== 'object' && Array.isArray(propKey) === false) {
return {
pass: false,
message: 'Expected wrapper to have prop "' + propKey + '", but it did not.',
negatedMessage: 'Expected wrapper not to have prop "' + propKey + '", but it did.',
contextualInformation: contextualInformation
pass: props.hasOwnProperty(propKey),
message: 'Expected <' + wrapperName + '> to have any value for the prop "' + propKey + '"',
negatedMessage: 'Expected <' + wrapperName + '> not to receive the prop "' + propKey + '"',
contextualInformation: {
actual: 'Actual props: ' + (0, _stringify4.default)(_defineProperty({}, propKey, props[propKey])),
expected: 'Expected props: ' + (0, _stringify4.default)(_defineProperty({}, propKey, propValue))
}
};
}
// key exists given above check, and we're not validating over values,
// so its always true unless the undefined value was provided explicitly
if (propValue === undefined && arguments.length === 2) {
var results = _reduceAssertionObject2.default.call(this, props, propKey, propValue);
var unmatchedKeys = results.unmatchedKeys.join(', ');
var contextualInformation = {
actual: 'Actual props: ' + (0, _stringify4.default)(results.actual),
expected: 'Expected props: ' + (0, _stringify4.default)(results.expected)
};
// error if some prop doesn't exist
if (results.missingKeys.length) {
var missingKeys = results.missingKeys.join(', ');
return {
pass: true,
message: 'Expected wrapper to have any value for the prop "' + propKey + '"',
negatedMessage: 'Expected wrapper not to receive the prop "' + propKey + '"',
pass: false,
message: 'Expected <' + wrapperName + '}> component to have props "' + missingKeys + '", but it did not.',
negatedMessage: 'Expected <' + wrapperName + '> component to not have a props "' + missingKeys + '", but it did.',
contextualInformation: contextualInformation

@@ -66,9 +74,6 @@ };

var equals = this && this.equals ? this.equals : _deepEqualIdent2.default;
var pass = equals(props[propKey], propValue);
return {
pass: pass,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> "' + propKey + '" prop values to match but they didn\'t.',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> "' + propKey + '" prop values not to match, but they did.',
pass: results.pass,
message: 'Expected <' + wrapperName + '> "' + unmatchedKeys + '" prop values to match but they didn\'t.',
negatedMessage: 'Expected <' + wrapperName + '> "' + unmatchedKeys + '" prop values not to match, but they did.',
contextualInformation: contextualInformation

@@ -75,0 +80,0 @@ };

@@ -7,6 +7,10 @@ 'use strict';

var _deepEqualIdent = require('deep-equal-ident');
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule toHaveStateAssertion
*
*/
var _deepEqualIdent2 = _interopRequireDefault(_deepEqualIdent);
var _name = require('../utils/name');

@@ -16,6 +20,10 @@

var _stringify7 = require('../utils/stringify');
var _reduceAssertionObject = require('../utils/reduceAssertionObject');
var _stringify8 = _interopRequireDefault(_stringify7);
var _reduceAssertionObject2 = _interopRequireDefault(_reduceAssertionObject);
var _stringify3 = require('../utils/stringify');
var _stringify4 = _interopRequireDefault(_stringify3);
var _single = require('../utils/single');

@@ -27,22 +35,18 @@

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 obj; } /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule toHaveStateAssertion
*
*/
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 obj; }
function toHaveState(enzymeWrapper, stateKey, stateValue) {
var state = enzymeWrapper.state();
var wrapperName = (0, _name2.default)(enzymeWrapper);
// error if the state key doesnt exist
if (!state.hasOwnProperty(stateKey)) {
// The API allows to check if a component has a prop in general by dropping the third
// argument.
if (stateValue === undefined && arguments.length === 2 && (typeof stateKey === 'undefined' ? 'undefined' : _typeof(stateKey)) !== 'object' && Array.isArray(stateKey) === false) {
return {
pass: false,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component state to have key of "' + stateKey + '"',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component state to not contain a key of "' + stateKey + '".',
pass: state.hasOwnProperty(stateKey),
message: 'Expected <' + wrapperName + '> to have any value for the prop "' + stateKey + '"',
negatedMessage: 'Expected <' + wrapperName + '> not to receive the prop "' + stateKey + '"',
contextualInformation: {
actual: 'Actual ' + (0, _stringify8.default)(_defineProperty({}, stateKey, state[stateKey])),
expected: 'Expected state: ' + (0, _stringify8.default)(_defineProperty({}, stateKey, stateValue))
actual: 'Actual props: ' + (0, _stringify4.default)(_defineProperty({}, stateKey, state[stateKey])),
expected: 'Expected props: ' + (0, _stringify4.default)(_defineProperty({}, stateKey, stateValue))
}

@@ -52,27 +56,25 @@ };

// key exists given above check, and we're not validating over values,
// so its always true unless the undefined value was provided explicitly
if (stateValue === undefined && arguments.length === 2) {
var results = _reduceAssertionObject2.default.call(this, state, stateKey, stateValue);
var unmatchedKeys = results.unmatchedKeys.join(', ');
var contextualInformation = {
actual: 'Actual state: ' + (0, _stringify4.default)(results.actual),
expected: 'Expected state: ' + (0, _stringify4.default)(results.expected)
};
// error if some state doesn't exist
if (results.missingKeys.length) {
var missingKeys = results.missingKeys.join(', ');
return {
pass: true,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component state to have key of "' + stateKey + '"',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component state to not contain a key of "' + stateKey + '".',
contextualInformation: {
actual: 'Actual ' + (0, _stringify8.default)(_defineProperty({}, stateKey, state[stateKey])),
expected: 'Expected state: ' + (0, _stringify8.default)(_defineProperty({}, stateKey, stateValue))
}
pass: false,
message: 'Expected <' + wrapperName + '> component state to have keys of "' + missingKeys + '"',
negatedMessage: 'Expected <' + wrapperName + '> component state to not contain a key of "' + missingKeys + '".',
contextualInformation: contextualInformation
};
}
var equals = this && this.equals ? this.equals : _deepEqualIdent2.default;
var pass = equals(state[stateKey], stateValue);
return {
pass: pass,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component state values to match for key "' + stateKey + '" but they didn\'t.',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component state values to be different for key "' + stateKey + '" but they didn\'t.',
contextualInformation: {
actual: 'Actual ' + (0, _stringify8.default)(_defineProperty({}, stateKey, state[stateKey])),
expected: 'Expected state: ' + (0, _stringify8.default)(_defineProperty({}, stateKey, stateValue))
}
pass: results.pass,
message: 'Expected <' + wrapperName + '> component state values to match for keys "' + unmatchedKeys + '" but they didn\'t.',
negatedMessage: 'Expected <' + wrapperName + '> component state values to be different for keys "' + unmatchedKeys + '" but they didn\'t.',
contextualInformation: contextualInformation
};

@@ -79,0 +81,0 @@ }

@@ -7,8 +7,12 @@ '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]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _deepEqualIdent = require('deep-equal-ident');
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]; } } } return target; }; /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule toHaveStyleAssertion
*
*/
var _deepEqualIdent2 = _interopRequireDefault(_deepEqualIdent);
var _name = require('../utils/name');

@@ -22,2 +26,6 @@

var _reduceAssertionObject = require('../utils/reduceAssertionObject');
var _reduceAssertionObject2 = _interopRequireDefault(_reduceAssertionObject);
var _html = require('../utils/html');

@@ -33,19 +41,28 @@

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 obj; } /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule toHaveStyleAssertion
*
*/
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 obj; }
function flattenStyle(style) {
if (!style) {
return undefined;
}
if (!Array.isArray(style)) {
return style;
}
return style.reduce(function (computedStyle, currentStyle) {
return _extends({}, computedStyle, flattenStyle(currentStyle));
}, undefined);
}
function toHaveStyle(enzymeWrapper, styleKey, styleValue) {
var style = flattenStyle(enzymeWrapper.prop('style'));
var wrapperName = (0, _name2.default)(enzymeWrapper);
// error if component doesnt have style
// 1. If the component doesn't have a style prop in general. That's an immediate failure.
if (!style) {
return {
pass: false,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component to have a style prop but it did not.',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component not to have a style prop but it did.',
message: 'Expected <' + wrapperName + '> component to have a style prop but it did not.',
negatedMessage: 'Expected <' + wrapperName + '> component not to have a style prop but it did.',
contextualInformation: {

@@ -57,8 +74,30 @@ actual: (0, _html2.default)(enzymeWrapper)

// error if the style key doesnt exist
if (!style.hasOwnProperty(styleKey)) {
// 2. If the assertion is to check if the component has a style in general. We need to make sure
// that its not an object and intended for the object assertion API.
// Then we have to make sure the style has that key.
if (styleKey === undefined && arguments.length === 2 && (typeof styleKey === 'undefined' ? 'undefined' : _typeof(styleKey)) !== 'object' && Array.isArray(styleKey) === false) {
return {
pass: style.hasOwnProperty(styleKey),
message: 'Expected <' + wrapperName + '> to have any value for the prop "' + styleKey + '"',
negatedMessage: 'Expected <' + wrapperName + '> not to receive the prop "' + styleKey + '"',
contextualInformation: {
actual: 'Actual props: ' + (0, _stringify4.default)(_defineProperty({}, styleKey, style[styleKey])),
expected: 'Expected props: ' + (0, _stringify4.default)(_defineProperty({}, styleKey, styleValue))
}
};
}
var results = _reduceAssertionObject2.default.call(this, style, styleKey, styleValue);
var unmatchedKeys = results.unmatchedKeys.join(', ');
var contextualInformation = {
actual: 'Actual style: ' + (0, _stringify4.default)(results.actual),
expected: 'Expected style: ' + (0, _stringify4.default)(results.expected)
};
if (results.missingKeys.length) {
var missingKeys = results.missingKeys.join(', ');
return {
pass: false,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component to have a style key of "' + styleKey + '" but it did not.',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component not to have a style key of "' + styleKey + '" but it did.',
message: 'Expected <' + wrapperName + '> component to have a style keys of "' + missingKeys + '" but it did not.',
negatedMessage: 'Expected <' + wrapperName + '> component not to have a style key of "' + missingKeys + '" but it did.',
contextualInformation: {

@@ -70,31 +109,11 @@ actual: (0, _html2.default)(enzymeWrapper)

var equals = this && this.equals ? this.equals : _deepEqualIdent2.default;
var pass = equals(style[styleKey], styleValue);
return {
pass: pass,
message: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component style values to match for key "' + styleKey + '", but they didn\'t',
negatedMessage: 'Expected <' + (0, _name2.default)(enzymeWrapper) + '> component style values to be different for key "' + styleKey + '", but they weren\'t',
contextualInformation: {
actual: 'Actual: ' + (0, _stringify4.default)(_defineProperty({}, styleKey, style[styleKey])),
expected: 'Expected: ' + (0, _stringify4.default)(_defineProperty({}, styleKey, styleValue))
}
pass: results.pass,
message: 'Expected <' + wrapperName + '> component style values to match for key "' + unmatchedKeys + '", but they didn\'t',
negatedMessage: 'Expected <' + wrapperName + '> component style values to be different for key "' + unmatchedKeys + '", but they weren\'t',
contextualInformation: contextualInformation
};
}
function flattenStyle(style) {
if (!style) {
return undefined;
}
if (!Array.isArray(style)) {
return style;
}
return style.reduce(function (computedStyle, currentStyle) {
return _extends({}, computedStyle, flattenStyle(currentStyle));
}, undefined);
}
exports.default = (0, _single2.default)(toHaveStyle);
module.exports = exports['default'];

@@ -15,10 +15,6 @@ 'use strict';

var _toBeEmpty = require('./assertions/toBeEmpty');
var _toBeEmptyRender = require('./assertions/toBeEmptyRender');
var _toBeEmpty2 = _interopRequireDefault(_toBeEmpty);
var _toBeEmptyRender2 = _interopRequireDefault(_toBeEmptyRender);
var _toBePresent = require('./assertions/toBePresent');
var _toBePresent2 = _interopRequireDefault(_toBePresent);
var _toContainReact = require('./assertions/toContainReact');

@@ -28,2 +24,6 @@

var _toExist = require('./assertions/toExist');
var _toExist2 = _interopRequireDefault(_toExist);
var _toHaveClassName = require('./assertions/toHaveClassName');

@@ -77,10 +77,22 @@

var _protectAssertion = require('./utils/protectAssertion');
var _protectAssertion2 = _interopRequireDefault(_protectAssertion);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
/**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule enzyme-matchrs
*
*/
var assertions = {
toBeChecked: _toBeChecked2.default,
toBeDisabled: _toBeDisabled2.default,
toBeEmpty: _toBeEmpty2.default,
toBePresent: _toBePresent2.default,
toBeEmptyRender: _toBeEmptyRender2.default,
toContainReact: _toContainReact2.default,
toExist: _toExist2.default,
toHaveClassName: _toHaveClassName2.default,

@@ -98,10 +110,10 @@ toHaveHTML: _toHaveHTML2.default,

toMatchElement: _toMatchElement2.default
}; /**
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. *
*
* @providesModule enzyme-matchrs
*
*/
};
// Protect all assertions from being called with not-enzyme-wrappers.
Object.keys(assertions).forEach(function (key) {
assertions[key] = (0, _protectAssertion2.default)(assertions[key]);
});
exports.default = assertions;
module.exports = exports['default'];
{
"name": "enzyme-matchers",
"version": "4.2.0",
"version": "5.0.0",
"description": "Testing Matchers for Enzyme",

@@ -37,9 +37,17 @@ "main": "lib/index.js",

},
"devDependencies": {
"enzyme": "^3.0.0",
"flow-bin": "^0.66.0"
},
"jest": {
"setupTestFrameworkScriptFile": "../../scripts/setup.js",
"roots": [
"<rootDir>/src"
],
"setupTestFrameworkScriptFile": "../jest-enzyme/lib/index.js",
"testEnvironment": "../jest-environment-enzyme/lib/index.js",
"testEnvironmentOptions": {
"adapter": "react16"
},
"verbose": true
}
}

@@ -5,3 +5,2 @@ # enzyme-matchers

![License](https://img.shields.io/npm/l/chai-enzyme.svg)
[![Circle CI](https://circleci.com/gh/blainekasten/enzyme-matchers/tree/master.svg?style=svg)](https://circleci.com/gh/blainekasten/enzyme-matchers/tree/master)

@@ -8,0 +7,0 @@ This package is primarily meant to be consumed by framework integrations within [this monorepo](https://github.com/blainekasten/enzyme-matchers). Though it can be used standalone. Look at the source if you want to see how it's used.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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