Socket
Socket
Sign inDemoInstall

@testing-library/jest-dom

Package Overview
Dependencies
Maintainers
15
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/jest-dom - npm Package Compare versions

Comparing version 5.16.5 to 5.17.0

dist/to-have-accessible-errormessage.js

3

dist/extend-expect.js
"use strict";
var extensions = _interopRequireWildcard(require("./matchers"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
expect.extend(extensions);

@@ -96,2 +96,8 @@ "use strict";

});
Object.defineProperty(exports, "toHaveAccessibleErrorMessage", {
enumerable: true,
get: function () {
return _toHaveAccessibleErrormessage.toHaveAccessibleErrorMessage;
}
});
Object.defineProperty(exports, "toHaveAccessibleName", {

@@ -163,49 +169,26 @@ enumerable: true,

});
var _toBeInTheDom = require("./to-be-in-the-dom");
var _toBeInTheDocument = require("./to-be-in-the-document");
var _toBeEmpty = require("./to-be-empty");
var _toBeEmptyDomElement = require("./to-be-empty-dom-element");
var _toContainElement = require("./to-contain-element");
var _toContainHtml = require("./to-contain-html");
var _toHaveTextContent = require("./to-have-text-content");
var _toHaveAccessibleDescription = require("./to-have-accessible-description");
var _toHaveAccessibleErrormessage = require("./to-have-accessible-errormessage");
var _toHaveAccessibleName = require("./to-have-accessible-name");
var _toHaveAttribute = require("./to-have-attribute");
var _toHaveClass = require("./to-have-class");
var _toHaveStyle = require("./to-have-style");
var _toHaveFocus = require("./to-have-focus");
var _toHaveFormValues = require("./to-have-form-values");
var _toBeVisible = require("./to-be-visible");
var _toBeDisabled = require("./to-be-disabled");
var _toBeRequired = require("./to-be-required");
var _toBeInvalid = require("./to-be-invalid");
var _toHaveValue = require("./to-have-value");
var _toHaveDisplayValue = require("./to-have-display-value");
var _toBeChecked = require("./to-be-checked");
var _toBePartiallyChecked = require("./to-be-partially-checked");
var _toHaveDescription = require("./to-have-description");
var _toHaveErrormessage = require("./to-have-errormessage");

@@ -7,18 +7,12 @@ "use strict";

exports.toBeChecked = toBeChecked;
var _ariaQuery = require("aria-query");
var _utils = require("./utils");
function toBeChecked(element) {
(0, _utils.checkHtmlElement)(element, toBeChecked, this);
const isValidInput = () => {
return element.tagName.toLowerCase() === 'input' && ['checkbox', 'radio'].includes(element.type);
};
const isValidAriaElement = () => {
return roleSupportsChecked(element.getAttribute('role')) && ['true', 'false'].includes(element.getAttribute('aria-checked'));
};
if (!isValidInput() && !isValidAriaElement()) {

@@ -30,3 +24,2 @@ return {

}
const isChecked = () => {

@@ -36,3 +29,2 @@ if (isValidInput()) return element.checked;

};
return {

@@ -46,3 +38,2 @@ pass: isChecked(),

}
function supportedRolesSentence() {

@@ -53,11 +44,8 @@ return (0, _utils.toSentence)(supportedRoles().map(role => `role="${role}"`), {

}
function supportedRoles() {
return _ariaQuery.roles.keys().filter(roleSupportsChecked);
}
function roleSupportsChecked(role) {
var _roles$get;
return ((_roles$get = _ariaQuery.roles.get(role)) == null ? void 0 : _roles$get.props['aria-checked']) !== undefined;
}

@@ -8,7 +8,6 @@ "use strict";

exports.toBeEnabled = toBeEnabled;
var _utils = require("./utils");
// form elements that support 'disabled'
const FORM_TAGS = ['fieldset', 'input', 'select', 'optgroup', 'option', 'button', 'textarea'];
/*

@@ -23,14 +22,12 @@ * According to specification:

*/
function isFirstLegendChildOfFieldset(element, parent) {
return (0, _utils.getTag)(element) === 'legend' && (0, _utils.getTag)(parent) === 'fieldset' && element.isSameNode(Array.from(parent.children).find(child => (0, _utils.getTag)(child) === 'legend'));
}
function isElementDisabledByParent(element, parent) {
return isElementDisabled(parent) && !isFirstLegendChildOfFieldset(element, parent);
}
function isCustomElement(tag) {
return tag.includes('-');
}
/*

@@ -40,4 +37,2 @@ * Only certain form elements and custom elements can actually be disabled:

*/
function canElementBeDisabled(element) {

@@ -47,7 +42,5 @@ const tag = (0, _utils.getTag)(element);

}
function isElementDisabled(element) {
return canElementBeDisabled(element) && element.hasAttribute('disabled');
}
function isAncestorDisabled(element) {

@@ -57,7 +50,5 @@ const parent = element.parentElement;

}
function isElementOrAncestorDisabled(element) {
return canElementBeDisabled(element) && (isElementDisabled(element) || isAncestorDisabled(element));
}
function toBeDisabled(element) {

@@ -74,3 +65,2 @@ (0, _utils.checkHtmlElement)(element, toBeDisabled, this);

}
function toBeEnabled(element) {

@@ -77,0 +67,0 @@ (0, _utils.checkHtmlElement)(element, toBeEnabled, this);

@@ -7,5 +7,3 @@ "use strict";

exports.toBeEmptyDOMElement = toBeEmptyDOMElement;
var _utils = require("./utils");
function toBeEmptyDOMElement(element) {

@@ -20,2 +18,3 @@ (0, _utils.checkHtmlElement)(element, toBeEmptyDOMElement, this);

}
/**

@@ -29,4 +28,2 @@ * Identifies if an element doesn't contain child nodes (excluding comments)

*/
function isEmptyElement(element) {

@@ -33,0 +30,0 @@ const nonCommentChildNodes = [...element.childNodes].filter(node => node.nodeType !== 8);

@@ -7,5 +7,3 @@ "use strict";

exports.toBeEmpty = toBeEmpty;
var _utils = require("./utils");
function toBeEmpty(element) {

@@ -12,0 +10,0 @@ (0, _utils.deprecate)('toBeEmpty', 'Please use instead toBeEmptyDOMElement for finding empty nodes in the DOM.');

@@ -7,5 +7,3 @@ "use strict";

exports.toBeInTheDocument = toBeInTheDocument;
var _utils = require("./utils");
function toBeInTheDocument(element) {

@@ -15,19 +13,16 @@ if (element !== null || !this.isNot) {

}
const pass = element === null ? false : element.ownerDocument === element.getRootNode({
composed: true
});
const errorFound = () => {
return `expected document not to contain element, found ${this.utils.stringify(element.cloneNode(true))} instead`;
};
const errorNotFound = () => {
return `element could not be found in the document`;
};
return {
pass,
message: () => {
return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toBeInTheDocument`, 'element', ''), '', // eslint-disable-next-line @babel/new-cap
return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toBeInTheDocument`, 'element', ''), '',
// eslint-disable-next-line @babel/new-cap
this.utils.RECEIVED_COLOR(this.isNot ? errorFound() : errorNotFound())].join('\n');

@@ -34,0 +29,0 @@ }

@@ -7,16 +7,11 @@ "use strict";

exports.toBeInTheDOM = toBeInTheDOM;
var _utils = require("./utils");
function toBeInTheDOM(element, container) {
(0, _utils.deprecate)('toBeInTheDOM', 'Please use toBeInTheDocument for searching the entire document and toContainElement for searching a specific container.');
if (element) {
(0, _utils.checkHtmlElement)(element, toBeInTheDOM, this);
}
if (container) {
(0, _utils.checkHtmlElement)(container, toBeInTheDOM, this);
}
return {

@@ -23,0 +18,0 @@ pass: container ? container.contains(element) : !!element,

@@ -8,18 +8,12 @@ "use strict";

exports.toBeValid = toBeValid;
var _utils = require("./utils");
const FORM_TAGS = ['form', 'input', 'select', 'textarea'];
function isElementHavingAriaInvalid(element) {
return element.hasAttribute('aria-invalid') && element.getAttribute('aria-invalid') !== 'false';
}
function isSupportsValidityMethod(element) {
return FORM_TAGS.includes((0, _utils.getTag)(element));
}
function isElementInvalid(element) {
const isHaveAriaInvalid = isElementHavingAriaInvalid(element);
if (isSupportsValidityMethod(element)) {

@@ -31,3 +25,2 @@ return isHaveAriaInvalid || !element.checkValidity();

}
function toBeInvalid(element) {

@@ -44,3 +37,2 @@ (0, _utils.checkHtmlElement)(element, toBeInvalid, this);

}
function toBeValid(element) {

@@ -47,0 +39,0 @@ (0, _utils.checkHtmlElement)(element, toBeValid, this);

@@ -7,16 +7,11 @@ "use strict";

exports.toBePartiallyChecked = toBePartiallyChecked;
var _utils = require("./utils");
function toBePartiallyChecked(element) {
(0, _utils.checkHtmlElement)(element, toBePartiallyChecked, this);
const isValidInput = () => {
return element.tagName.toLowerCase() === 'input' && element.type === 'checkbox';
};
const isValidAriaElement = () => {
return element.getAttribute('role') === 'checkbox';
};
if (!isValidInput() && !isValidAriaElement()) {

@@ -28,13 +23,9 @@ return {

}
const isPartiallyChecked = () => {
const isAriaMixed = element.getAttribute('aria-checked') === 'mixed';
if (isValidInput()) {
return element.indeterminate || isAriaMixed;
}
return isAriaMixed;
};
return {

@@ -41,0 +32,0 @@ pass: isPartiallyChecked(),

@@ -7,5 +7,3 @@ "use strict";

exports.toBeRequired = toBeRequired;
var _utils = require("./utils");
// form elements that support 'required'

@@ -16,15 +14,11 @@ const FORM_TAGS = ['select', 'textarea'];

const SUPPORTED_ARIA_ROLES = ['combobox', 'gridcell', 'radiogroup', 'spinbutton', 'tree'];
function isRequiredOnFormTagsExceptInput(element) {
return FORM_TAGS.includes((0, _utils.getTag)(element)) && element.hasAttribute('required');
}
function isRequiredOnSupportedInput(element) {
return (0, _utils.getTag)(element) === 'input' && element.hasAttribute('required') && (element.hasAttribute('type') && !UNSUPPORTED_INPUT_TYPES.includes(element.getAttribute('type')) || !element.hasAttribute('type'));
}
function isElementRequiredByARIA(element) {
return element.hasAttribute('aria-required') && element.getAttribute('aria-required') === 'true' && (ARIA_FORM_TAGS.includes((0, _utils.getTag)(element)) || element.hasAttribute('role') && SUPPORTED_ARIA_ROLES.includes(element.getAttribute('role')));
}
function toBeRequired(element) {

@@ -31,0 +25,0 @@ (0, _utils.checkHtmlElement)(element, toBeRequired, this);

@@ -7,5 +7,3 @@ "use strict";

exports.toBeVisible = toBeVisible;
var _utils = require("./utils");
function isStyleVisible(element) {

@@ -22,6 +20,4 @@ const {

}
function isAttributeVisible(element, previousElement) {
let detailsVisibility;
if (previousElement) {

@@ -32,10 +28,7 @@ detailsVisibility = element.nodeName === 'DETAILS' && previousElement.nodeName !== 'SUMMARY' ? element.hasAttribute('open') : true;

}
return !element.hasAttribute('hidden') && detailsVisibility;
}
function isElementVisible(element, previousElement) {
return isStyleVisible(element) && isAttributeVisible(element, previousElement) && (!element.parentElement || isElementVisible(element.parentElement, element));
}
function toBeVisible(element) {

@@ -42,0 +35,0 @@ (0, _utils.checkHtmlElement)(element, toBeVisible, this);

@@ -7,16 +7,13 @@ "use strict";

exports.toContainElement = toContainElement;
var _utils = require("./utils");
function toContainElement(container, element) {
(0, _utils.checkHtmlElement)(container, toContainElement, this);
if (element !== null) {
(0, _utils.checkHtmlElement)(element, toContainElement, this);
}
return {
pass: container.contains(element),
message: () => {
return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toContainElement`, 'element', 'element'), '', // eslint-disable-next-line @babel/new-cap
return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toContainElement`, 'element', 'element'), '',
// eslint-disable-next-line @babel/new-cap
this.utils.RECEIVED_COLOR(`${this.utils.stringify(container.cloneNode(false))} ${this.isNot ? 'contains:' : 'does not contain:'} ${this.utils.stringify(element ? element.cloneNode(false) : element)}

@@ -23,0 +20,0 @@ `)].join('\n');

@@ -7,5 +7,3 @@ "use strict";

exports.toContainHTML = toContainHTML;
var _utils = require("./utils");
function getNormalizedHtml(container, htmlText) {

@@ -16,14 +14,12 @@ const div = container.ownerDocument.createElement('div');

}
function toContainHTML(container, htmlText) {
(0, _utils.checkHtmlElement)(container, toContainHTML, this);
if (typeof htmlText !== 'string') {
throw new Error(`.toContainHTML() expects a string value, got ${htmlText}`);
}
return {
pass: container.outerHTML.includes(getNormalizedHtml(container, htmlText)),
message: () => {
return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toContainHTML`, 'element', ''), 'Expected:', // eslint-disable-next-line @babel/new-cap
return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toContainHTML`, 'element', ''), 'Expected:',
// eslint-disable-next-line @babel/new-cap
` ${this.utils.EXPECTED_COLOR(htmlText)}`, 'Received:', ` ${this.utils.printReceived(container.cloneNode(true))}`].join('\n');

@@ -30,0 +26,0 @@ }

@@ -7,7 +7,4 @@ "use strict";

exports.toHaveAccessibleDescription = toHaveAccessibleDescription;
var _domAccessibilityApi = require("dom-accessibility-api");
var _utils = require("./utils");
function toHaveAccessibleDescription(htmlElement, expectedAccessibleDescription) {

@@ -18,3 +15,2 @@ (0, _utils.checkHtmlElement)(htmlElement, toHaveAccessibleDescription, this);

let pass = false;
if (missingExpectedValue) {

@@ -27,3 +23,2 @@ // When called without an expected value we only want to validate that the element has an

}
return {

@@ -30,0 +25,0 @@ pass,

@@ -7,7 +7,4 @@ "use strict";

exports.toHaveAccessibleName = toHaveAccessibleName;
var _domAccessibilityApi = require("dom-accessibility-api");
var _utils = require("./utils");
function toHaveAccessibleName(htmlElement, expectedAccessibleName) {

@@ -18,3 +15,2 @@ (0, _utils.checkHtmlElement)(htmlElement, toHaveAccessibleName, this);

let pass = false;
if (missingExpectedValue) {

@@ -27,3 +23,2 @@ // When called without an expected value we only want to validate that the element has an

}
return {

@@ -30,0 +25,0 @@ pass,

@@ -7,13 +7,9 @@ "use strict";

exports.toHaveAttribute = toHaveAttribute;
var _utils = require("./utils");
function printAttribute(stringify, name, value) {
return value === undefined ? name : `${name}=${stringify(value)}`;
}
function getAttributeComment(stringify, name, value) {
return value === undefined ? `element.hasAttribute(${stringify(name)})` : `element.getAttribute(${stringify(name)}) === ${stringify(value)}`;
}
function toHaveAttribute(htmlElement, name, expectedValue) {

@@ -20,0 +16,0 @@ (0, _utils.checkHtmlElement)(htmlElement, toHaveAttribute, this);

@@ -7,9 +7,6 @@ "use strict";

exports.toHaveClass = toHaveClass;
var _utils = require("./utils");
function getExpectedClassNamesAndOptions(params) {
const lastParam = params.pop();
let expectedClassNames, options;
if (typeof lastParam === 'object') {

@@ -24,3 +21,2 @@ expectedClassNames = params;

}
return {

@@ -31,3 +27,2 @@ expectedClassNames,

}
function splitClassNames(str) {

@@ -37,10 +32,7 @@ if (!str) {

}
return str.split(/\s+/).filter(s => s.length > 0);
}
function isSubset(subset, superset) {
return subset.every(item => superset.includes(item));
}
function toHaveClass(htmlElement, ...params) {

@@ -54,3 +46,2 @@ (0, _utils.checkHtmlElement)(htmlElement, toHaveClass, this);

const expected = expectedClassNames.reduce((acc, className) => acc.concat(splitClassNames(className)), []);
if (options.exact) {

@@ -65,3 +56,2 @@ return {

}
return expected.length > 0 ? {

@@ -68,0 +58,0 @@ pass: isSubset(expected, received),

@@ -7,5 +7,3 @@ "use strict";

exports.toHaveDescription = toHaveDescription;
var _utils = require("./utils");
// See algoritm: https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_description

@@ -19,3 +17,2 @@ function toHaveDescription(htmlElement, checkWith) {

let description = '';
if (descriptionIDs.length > 0) {

@@ -26,3 +23,2 @@ const document = htmlElement.ownerDocument;

}
return {

@@ -29,0 +25,0 @@ pass: expectsDescription ? checkWith instanceof RegExp ? checkWith.test(description) : this.equals(description, checkWith) : Boolean(description),

@@ -7,17 +7,12 @@ "use strict";

exports.toHaveDisplayValue = toHaveDisplayValue;
var _utils = require("./utils");
function toHaveDisplayValue(htmlElement, expectedValue) {
(0, _utils.checkHtmlElement)(htmlElement, toHaveDisplayValue, this);
const tagName = htmlElement.tagName.toLowerCase();
if (!['select', 'input', 'textarea'].includes(tagName)) {
throw new Error('.toHaveDisplayValue() currently supports only input, textarea or select elements, try with another matcher instead.');
}
if (tagName === 'input' && ['radio', 'checkbox'].includes(htmlElement.type)) {
throw new Error(`.toHaveDisplayValue() currently does not support input[type="${htmlElement.type}"], try with another matcher instead.`);
}
const values = getValues(tagName, htmlElement);

@@ -33,9 +28,7 @@ const expectedValues = getExpectedValues(expectedValue);

}
function getValues(tagName, htmlElement) {
return tagName === 'select' ? Array.from(htmlElement).filter(option => option.selected).map(option => option.textContent) : [htmlElement.value];
}
function getExpectedValues(expectedValue) {
return expectedValue instanceof Array ? expectedValue : [expectedValue];
}

@@ -7,9 +7,7 @@ "use strict";

exports.toHaveErrorMessage = toHaveErrorMessage;
var _utils = require("./utils");
// See aria-errormessage spec https://www.w3.org/TR/wai-aria-1.2/#aria-errormessage
function toHaveErrorMessage(htmlElement, checkWith) {
(0, _utils.deprecate)('toHaveErrorMessage', 'Please use toHaveAccessibleErrorMessage.');
(0, _utils.checkHtmlElement)(htmlElement, toHaveErrorMessage, this);
if (!htmlElement.hasAttribute('aria-invalid') || htmlElement.getAttribute('aria-invalid') === 'false') {

@@ -24,3 +22,2 @@ const not = this.isNot ? '.not' : '';

}
const expectsErrorMessage = checkWith !== undefined;

@@ -30,3 +27,2 @@ const errormessageIDRaw = htmlElement.getAttribute('aria-errormessage') || '';

let errormessage = '';
if (errormessageIDs.length > 0) {

@@ -37,3 +33,2 @@ const document = htmlElement.ownerDocument;

}
return {

@@ -40,0 +35,0 @@ pass: expectsErrorMessage ? checkWith instanceof RegExp ? checkWith.test(errormessage) : this.equals(errormessage, checkWith) : Boolean(errormessage),

@@ -7,5 +7,3 @@ "use strict";

exports.toHaveFocus = toHaveFocus;
var _utils = require("./utils");
function toHaveFocus(element) {

@@ -12,0 +10,0 @@ (0, _utils.checkHtmlElement)(element, toHaveFocus, this);

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,13 +8,7 @@ value: true

exports.toHaveFormValues = toHaveFormValues;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _isEqualWith = _interopRequireDefault(require("lodash/isEqualWith"));
var _uniq = _interopRequireDefault(require("lodash/uniq"));
var _css = _interopRequireDefault(require("css.escape"));
var _utils = require("./utils");
// Returns the combined value of several elements that have the same name

@@ -25,7 +18,5 @@ // e.g. radio buttons or groups of checkboxes

const types = (0, _uniq.default)(elements.map(element => element.type));
if (types.length !== 1) {
throw new Error('Multiple form elements with the same name must be of the same type');
}
switch (types[0]) {

@@ -37,6 +28,4 @@ case 'radio':

}
case 'checkbox':
return elements.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value);
default:

@@ -47,7 +36,5 @@ // NOTE: Not even sure this is a valid use case, but just in case...

}
function getFormValue(container, name) {
const elements = [...container.querySelectorAll(`[name="${(0, _css.default)(name)}"]`)];
/* istanbul ignore if */
if (elements.length === 0) {

@@ -60,13 +47,11 @@ return undefined; // shouldn't happen, but just in case

return (0, _utils.getSingleElementValue)(elements[0]);
default:
return getMultiElementValue(elements);
}
} // Strips the `[]` suffix off a form value name
}
// Strips the `[]` suffix off a form value name
function getPureName(name) {
return /\[\]$/.test(name) ? name.slice(0, -2) : name;
}
function getAllFormValues(container) {

@@ -78,6 +63,4 @@ const names = Array.from(container.elements).map(element => element.name);

}
function toHaveFormValues(formElement, expectedValues) {
(0, _utils.checkHtmlElement)(formElement, toHaveFormValues, this);
if (!formElement.elements) {

@@ -87,3 +70,2 @@ // TODO: Change condition to use instanceof against the appropriate element classes instead

}
const formValues = getAllFormValues(formElement);

@@ -90,0 +72,0 @@ return {

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,10 +8,8 @@ value: true

exports.toHaveStyle = toHaveStyle;
var _chalk = _interopRequireDefault(require("chalk"));
var _utils = require("./utils");
function getStyleDeclaration(document, css) {
const styles = {}; // The next block is necessary to normalize colors
const styles = {};
// The next block is necessary to normalize colors
const copy = document.createElement('div');

@@ -25,13 +22,11 @@ Object.keys(css).forEach(property => {

}
function isSubset(styles, computedStyle) {
return !!Object.keys(styles).length && Object.entries(styles).every(([prop, value]) => computedStyle[prop] === value || computedStyle.getPropertyValue(prop.toLowerCase()) === value);
}
function printoutStyles(styles) {
return Object.keys(styles).sort().map(prop => `${prop}: ${styles[prop]};`).join('\n');
} // Highlights only style rules that were expected but were not found in the
}
// Highlights only style rules that were expected but were not found in the
// received computed styles
function expectedDiff(diffFn, expected, computedStyles) {

@@ -41,7 +36,6 @@ const received = Array.from(computedStyles).filter(prop => expected[prop] !== undefined).reduce((obj, prop) => Object.assign(obj, {

}), {});
const diffOutput = diffFn(printoutStyles(expected), printoutStyles(received)); // Remove the "+ Received" annotation because this is a one-way diff
const diffOutput = diffFn(printoutStyles(expected), printoutStyles(received));
// Remove the "+ Received" annotation because this is a one-way diff
return diffOutput.replace(`${_chalk.default.red('+ Received')}\n`, '');
}
function toHaveStyle(htmlElement, css) {

@@ -48,0 +42,0 @@ (0, _utils.checkHtmlElement)(htmlElement, toHaveStyle, this);

@@ -7,5 +7,3 @@ "use strict";

exports.toHaveTextContent = toHaveTextContent;
var _utils = require("./utils");
function toHaveTextContent(node, checkWith, options = {

@@ -12,0 +10,0 @@ normalizeWhitespace: true

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,14 +8,9 @@ value: true

exports.toHaveValue = toHaveValue;
var _isEqualWith = _interopRequireDefault(require("lodash/isEqualWith"));
var _utils = require("./utils");
function toHaveValue(htmlElement, expectedValue) {
(0, _utils.checkHtmlElement)(htmlElement, toHaveValue, this);
if (htmlElement.tagName.toLowerCase() === 'input' && ['checkbox', 'radio'].includes(htmlElement.type)) {
throw new Error('input with type=checkbox or type=radio cannot be used with .toHaveValue(). Use .toBeChecked() for type=checkbox or .toHaveFormValues() instead');
}
const receivedValue = (0, _utils.getSingleElementValue)(htmlElement);

@@ -26,3 +20,2 @@ const expectsValue = expectedValue !== undefined;

let receivedTypedValue = receivedValue;
if (expectedValue == receivedValue && expectedValue !== receivedValue) {

@@ -32,3 +25,2 @@ expectedTypedValue = `${expectedValue} (${typeof expectedValue})`;

}
return {

@@ -35,0 +27,0 @@ pass: expectsValue ? (0, _isEqualWith.default)(receivedValue, expectedValue, _utils.compareArraysAsSet) : Boolean(receivedValue),

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -20,32 +19,25 @@ value: true

exports.toSentence = toSentence;
var _redent = _interopRequireDefault(require("redent"));
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
var _cssTools = require("@adobe/css-tools");
class GenericTypeError extends Error {
constructor(expectedString, received, matcherFn, context) {
super();
/* istanbul ignore next */
if (Error.captureStackTrace) {
Error.captureStackTrace(this, matcherFn);
}
let withType = '';
try {
withType = context.utils.printWithType('Received', received, context.utils.printReceived);
} catch (e) {// Can throw for Document:
} catch (e) {
// Can throw for Document:
// https://github.com/jsdom/jsdom/issues/2304
}
this.message = [context.utils.matcherHint(`${context.isNot ? '.not' : ''}.${matcherFn.name}`, 'received', ''), '', // eslint-disable-next-line @babel/new-cap
this.message = [context.utils.matcherHint(`${context.isNot ? '.not' : ''}.${matcherFn.name}`, 'received', ''), '',
// eslint-disable-next-line @babel/new-cap
`${context.utils.RECEIVED_COLOR('received')} value must ${expectedString}.`, withType].join('\n');
}
}
class HtmlElementTypeError extends GenericTypeError {

@@ -55,7 +47,4 @@ constructor(...args) {

}
}
exports.HtmlElementTypeError = HtmlElementTypeError;
class NodeTypeError extends GenericTypeError {

@@ -65,7 +54,4 @@ constructor(...args) {

}
}
exports.NodeTypeError = NodeTypeError;
function checkHasWindow(htmlElement, ErrorClass, ...args) {

@@ -76,7 +62,5 @@ if (!htmlElement || !htmlElement.ownerDocument || !htmlElement.ownerDocument.defaultView) {

}
function checkNode(node, ...args) {
checkHasWindow(node, NodeTypeError, ...args);
const window = node.ownerDocument.defaultView;
if (!(node instanceof window.Node)) {

@@ -86,7 +70,5 @@ throw new NodeTypeError(node, ...args);

}
function checkHtmlElement(htmlElement, ...args) {
checkHasWindow(htmlElement, HtmlElementTypeError, ...args);
const window = htmlElement.ownerDocument.defaultView;
if (!(htmlElement instanceof window.HTMLElement) && !(htmlElement instanceof window.SVGElement)) {

@@ -96,19 +78,17 @@ throw new HtmlElementTypeError(htmlElement, ...args);

}
class InvalidCSSError extends Error {
constructor(received, matcherFn, context) {
super();
/* istanbul ignore next */
if (Error.captureStackTrace) {
Error.captureStackTrace(this, matcherFn);
}
this.message = [received.message, '', // eslint-disable-next-line @babel/new-cap
context.utils.RECEIVED_COLOR(`Failing css:`), // eslint-disable-next-line @babel/new-cap
this.message = [received.message, '',
// eslint-disable-next-line @babel/new-cap
context.utils.RECEIVED_COLOR(`Failing css:`),
// eslint-disable-next-line @babel/new-cap
context.utils.RECEIVED_COLOR(`${received.css}`)].join('\n');
}
}
function parseCSS(css, ...args) {

@@ -118,3 +98,2 @@ const ast = (0, _cssTools.parse)(`selector { ${css} }`, {

}).stylesheet;
if (ast.parsingErrors && ast.parsingErrors.length > 0) {

@@ -130,3 +109,2 @@ const {

}
const parsedRules = ast.rules[0].declarations.filter(d => d.type === 'declaration').reduce((obj, {

@@ -140,13 +118,12 @@ property,

}
function display(context, value) {
return typeof value === 'string' ? value : context.utils.stringify(value);
}
function getMessage(context, matcher, expectedLabel, expectedValue, receivedLabel, receivedValue) {
return [`${matcher}\n`, // eslint-disable-next-line @babel/new-cap
`${expectedLabel}:\n${context.utils.EXPECTED_COLOR((0, _redent.default)(display(context, expectedValue), 2))}`, // eslint-disable-next-line @babel/new-cap
return [`${matcher}\n`,
// eslint-disable-next-line @babel/new-cap
`${expectedLabel}:\n${context.utils.EXPECTED_COLOR((0, _redent.default)(display(context, expectedValue), 2))}`,
// eslint-disable-next-line @babel/new-cap
`${receivedLabel}:\n${context.utils.RECEIVED_COLOR((0, _redent.default)(display(context, receivedValue), 2))}`].join('\n');
}
function matches(textToMatch, matcher) {

@@ -159,3 +136,2 @@ if (matcher instanceof RegExp) {

}
function deprecate(name, replacementText) {

@@ -166,11 +142,8 @@ // Notify user that they are using deprecated functionality.

}
function normalize(text) {
return text.replace(/\s+/g, ' ').trim();
}
function getTag(element) {
return element.tagName && element.tagName.toLowerCase();
}
function getSelectValue({

@@ -181,3 +154,2 @@ multiple,

const selectedOptions = [...options].filter(option => option.selected);
if (multiple) {

@@ -187,4 +159,2 @@ return [...selectedOptions].map(opt => opt.value);

/* istanbul ignore if */
if (selectedOptions.length === 0) {

@@ -196,3 +166,2 @@ return undefined; // Couldn't make this happen, but just in case

}
function getInputValue(inputElement) {

@@ -202,6 +171,4 @@ switch (inputElement.type) {

return inputElement.value === '' ? null : Number(inputElement.value);
case 'checkbox':
return inputElement.checked;
default:

@@ -211,3 +178,2 @@ return inputElement.value;

}
function getSingleElementValue(element) {

@@ -218,10 +184,7 @@ /* istanbul ignore if */

}
switch (element.tagName.toLowerCase()) {
case 'input':
return getInputValue(element);
case 'select':
return getSelectValue(element);
default:

@@ -231,3 +194,2 @@ return element.value;

}
function compareArraysAsSet(a, b) {

@@ -237,6 +199,4 @@ if (Array.isArray(a) && Array.isArray(b)) {

}
return undefined;
}
function toSentence(array, {

@@ -243,0 +203,0 @@ wordConnector = ', ',

{
"name": "@testing-library/jest-dom",
"version": "5.16.5",
"version": "5.17.0",
"description": "Custom jest matchers to test the state of the DOM",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is too big to display

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