Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into update-typescript-typings
Browse files Browse the repository at this point in the history
  • Loading branch information
shadrech committed Nov 16, 2019
2 parents da857e6 + b315404 commit 420bf58
Show file tree
Hide file tree
Showing 21 changed files with 1,017 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,6 +1,5 @@
node_modules
coverage
dist
.opt-in
.opt-out
.DS_Store
Expand Down
7 changes: 7 additions & 0 deletions dist/extend-expect.js
@@ -0,0 +1,7 @@
"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var extensions = _interopRequireWildcard(require("./index"));

expect.extend(extensions);
153 changes: 153 additions & 0 deletions dist/index.js
@@ -0,0 +1,153 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "toBeInTheDOM", {
enumerable: true,
get: function () {
return _toBeInTheDom.toBeInTheDOM;
}
});
Object.defineProperty(exports, "toBeInTheDocument", {
enumerable: true,
get: function () {
return _toBeInTheDocument.toBeInTheDocument;
}
});
Object.defineProperty(exports, "toBeEmpty", {
enumerable: true,
get: function () {
return _toBeEmpty.toBeEmpty;
}
});
Object.defineProperty(exports, "toContainElement", {
enumerable: true,
get: function () {
return _toContainElement.toContainElement;
}
});
Object.defineProperty(exports, "toContainHTML", {
enumerable: true,
get: function () {
return _toContainHtml.toContainHTML;
}
});
Object.defineProperty(exports, "toHaveTextContent", {
enumerable: true,
get: function () {
return _toHaveTextContent.toHaveTextContent;
}
});
Object.defineProperty(exports, "toHaveAttribute", {
enumerable: true,
get: function () {
return _toHaveAttribute.toHaveAttribute;
}
});
Object.defineProperty(exports, "toHaveClass", {
enumerable: true,
get: function () {
return _toHaveClass.toHaveClass;
}
});
Object.defineProperty(exports, "toHaveStyle", {
enumerable: true,
get: function () {
return _toHaveStyle.toHaveStyle;
}
});
Object.defineProperty(exports, "toHaveFocus", {
enumerable: true,
get: function () {
return _toHaveFocus.toHaveFocus;
}
});
Object.defineProperty(exports, "toHaveFormValues", {
enumerable: true,
get: function () {
return _toHaveFormValues.toHaveFormValues;
}
});
Object.defineProperty(exports, "toBeVisible", {
enumerable: true,
get: function () {
return _toBeVisible.toBeVisible;
}
});
Object.defineProperty(exports, "toBeDisabled", {
enumerable: true,
get: function () {
return _toBeDisabled.toBeDisabled;
}
});
Object.defineProperty(exports, "toBeEnabled", {
enumerable: true,
get: function () {
return _toBeDisabled.toBeEnabled;
}
});
Object.defineProperty(exports, "toBeRequired", {
enumerable: true,
get: function () {
return _toBeRequired.toBeRequired;
}
});
Object.defineProperty(exports, "toBeInvalid", {
enumerable: true,
get: function () {
return _toBeInvalid.toBeInvalid;
}
});
Object.defineProperty(exports, "toBeValid", {
enumerable: true,
get: function () {
return _toBeInvalid.toBeValid;
}
});
Object.defineProperty(exports, "toHaveValue", {
enumerable: true,
get: function () {
return _toHaveValue.toHaveValue;
}
});
Object.defineProperty(exports, "toBeChecked", {
enumerable: true,
get: function () {
return _toBeChecked.toBeChecked;
}
});

var _toBeInTheDom = require("./to-be-in-the-dom");

var _toBeInTheDocument = require("./to-be-in-the-document");

var _toBeEmpty = require("./to-be-empty");

var _toContainElement = require("./to-contain-element");

var _toContainHtml = require("./to-contain-html");

var _toHaveTextContent = require("./to-have-text-content");

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 _toBeChecked = require("./to-be-checked");
40 changes: 40 additions & 0 deletions dist/to-be-checked.js
@@ -0,0 +1,40 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toBeChecked = toBeChecked;

var _jestMatcherUtils = require("jest-matcher-utils");

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);
};

if (!isValidInput() && !(() => {
return ['checkbox', 'radio'].includes(element.getAttribute('role')) && ['true', 'false'].includes(element.getAttribute('aria-checked'));
})()) {
return {
pass: false,
message: () => 'only inputs with type="checkbox" or type="radio" or elements with role="checkbox" or role="radio" and a valid aria-checked attribute can be used with .toBeChecked(). Use .toHaveValue() instead'
};
}

const isChecked = () => {
if (isValidInput()) return element.checked;
return element.getAttribute('aria-checked') === 'true';
};

return {
pass: isChecked(),
message: () => {
const is = isChecked() ? 'is' : 'is not';
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeChecked`, 'element', ''), '', `Received element ${is} checked:`, ` ${(0, _jestMatcherUtils.printReceived)(element.cloneNode(false))}`].join('\n');
}
};
}
63 changes: 63 additions & 0 deletions dist/to-be-disabled.js
@@ -0,0 +1,63 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toBeDisabled = toBeDisabled;
exports.toBeEnabled = toBeEnabled;

var _jestMatcherUtils = require("jest-matcher-utils");

var _utils = require("./utils");

const FORM_TAGS = ['fieldset', 'input', 'select', 'optgroup', 'option', 'button', 'textarea'];
/*
* According to specification:
* If <fieldset> is disabled, the form controls that are its descendants,
* except descendants of its first optional <legend> element, are disabled
*
* https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
*
* This method tests whether element is first legend child of fieldset parent
*/

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 isElementDisabled(element) {
return FORM_TAGS.includes((0, _utils.getTag)(element)) && element.hasAttribute('disabled');
}

function isAncestorDisabled(element) {
const parent = element.parentElement;
return Boolean(parent) && (isElementDisabledByParent(element, parent) || isAncestorDisabled(parent));
}

function toBeDisabled(element) {
(0, _utils.checkHtmlElement)(element, toBeDisabled, this);
const isDisabled = isElementDisabled(element) || isAncestorDisabled(element);
return {
pass: isDisabled,
message: () => {
const is = isDisabled ? 'is' : 'is not';
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeDisabled`, 'element', ''), '', `Received element ${is} disabled:`, ` ${(0, _jestMatcherUtils.printReceived)(element.cloneNode(false))}`].join('\n');
}
};
}

function toBeEnabled(element) {
(0, _utils.checkHtmlElement)(element, toBeEnabled, this);
const isEnabled = !(isElementDisabled(element) || isAncestorDisabled(element));
return {
pass: isEnabled,
message: () => {
const is = isEnabled ? 'is' : 'is not';
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeEnabled`, 'element', ''), '', `Received element ${is} enabled:`, ` ${(0, _jestMatcherUtils.printReceived)(element.cloneNode(false))}`].join('\n');
}
};
}
20 changes: 20 additions & 0 deletions dist/to-be-empty.js
@@ -0,0 +1,20 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toBeEmpty = toBeEmpty;

var _jestMatcherUtils = require("jest-matcher-utils");

var _utils = require("./utils");

function toBeEmpty(element) {
(0, _utils.checkHtmlElement)(element, toBeEmpty, this);
return {
pass: element.innerHTML === '',
message: () => {
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeEmpty`, 'element', ''), '', 'Received:', ` ${(0, _jestMatcherUtils.printReceived)(element.innerHTML)}`].join('\n');
}
};
}
33 changes: 33 additions & 0 deletions dist/to-be-in-the-document.js
@@ -0,0 +1,33 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toBeInTheDocument = toBeInTheDocument;

var _jestMatcherUtils = require("jest-matcher-utils");

var _utils = require("./utils");

function toBeInTheDocument(element) {
if (element !== null || !this.isNot) {
(0, _utils.checkHtmlElement)(element, toBeInTheDocument, this);
}

const pass = element === null ? false : element.ownerDocument.contains(element);

const errorFound = () => {
return `expected document not to contain element, found ${(0, _jestMatcherUtils.stringify)(element.cloneNode(true))} instead`;
};

const errorNotFound = () => {
return `element could not be found in the document`;
};

return {
pass,
message: () => {
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeInTheDocument`, 'element', ''), '', (0, _jestMatcherUtils.RECEIVED_COLOR)(this.isNot ? errorFound() : errorNotFound())].join('\n');
}
};
}
29 changes: 29 additions & 0 deletions dist/to-be-in-the-dom.js
@@ -0,0 +1,29 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toBeInTheDOM = toBeInTheDOM;

var _jestMatcherUtils = require("jest-matcher-utils");

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 {
pass: container ? container.contains(element) : !!element,
message: () => {
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeInTheDOM`, 'element', ''), '', 'Received:', ` ${(0, _jestMatcherUtils.printReceived)(element ? element.cloneNode(false) : element)}`].join('\n');
}
};
}

0 comments on commit 420bf58

Please sign in to comment.