Skip to content

Commit 420bf58

Browse files
committed
Merge remote-tracking branch 'origin' into update-typescript-typings
2 parents da857e6 + b315404 commit 420bf58

21 files changed

+1017
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules
22
coverage
3-
dist
43
.opt-in
54
.opt-out
65
.DS_Store

dist/extend-expect.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4+
5+
var extensions = _interopRequireWildcard(require("./index"));
6+
7+
expect.extend(extensions);

dist/index.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
Object.defineProperty(exports, "toBeInTheDOM", {
7+
enumerable: true,
8+
get: function () {
9+
return _toBeInTheDom.toBeInTheDOM;
10+
}
11+
});
12+
Object.defineProperty(exports, "toBeInTheDocument", {
13+
enumerable: true,
14+
get: function () {
15+
return _toBeInTheDocument.toBeInTheDocument;
16+
}
17+
});
18+
Object.defineProperty(exports, "toBeEmpty", {
19+
enumerable: true,
20+
get: function () {
21+
return _toBeEmpty.toBeEmpty;
22+
}
23+
});
24+
Object.defineProperty(exports, "toContainElement", {
25+
enumerable: true,
26+
get: function () {
27+
return _toContainElement.toContainElement;
28+
}
29+
});
30+
Object.defineProperty(exports, "toContainHTML", {
31+
enumerable: true,
32+
get: function () {
33+
return _toContainHtml.toContainHTML;
34+
}
35+
});
36+
Object.defineProperty(exports, "toHaveTextContent", {
37+
enumerable: true,
38+
get: function () {
39+
return _toHaveTextContent.toHaveTextContent;
40+
}
41+
});
42+
Object.defineProperty(exports, "toHaveAttribute", {
43+
enumerable: true,
44+
get: function () {
45+
return _toHaveAttribute.toHaveAttribute;
46+
}
47+
});
48+
Object.defineProperty(exports, "toHaveClass", {
49+
enumerable: true,
50+
get: function () {
51+
return _toHaveClass.toHaveClass;
52+
}
53+
});
54+
Object.defineProperty(exports, "toHaveStyle", {
55+
enumerable: true,
56+
get: function () {
57+
return _toHaveStyle.toHaveStyle;
58+
}
59+
});
60+
Object.defineProperty(exports, "toHaveFocus", {
61+
enumerable: true,
62+
get: function () {
63+
return _toHaveFocus.toHaveFocus;
64+
}
65+
});
66+
Object.defineProperty(exports, "toHaveFormValues", {
67+
enumerable: true,
68+
get: function () {
69+
return _toHaveFormValues.toHaveFormValues;
70+
}
71+
});
72+
Object.defineProperty(exports, "toBeVisible", {
73+
enumerable: true,
74+
get: function () {
75+
return _toBeVisible.toBeVisible;
76+
}
77+
});
78+
Object.defineProperty(exports, "toBeDisabled", {
79+
enumerable: true,
80+
get: function () {
81+
return _toBeDisabled.toBeDisabled;
82+
}
83+
});
84+
Object.defineProperty(exports, "toBeEnabled", {
85+
enumerable: true,
86+
get: function () {
87+
return _toBeDisabled.toBeEnabled;
88+
}
89+
});
90+
Object.defineProperty(exports, "toBeRequired", {
91+
enumerable: true,
92+
get: function () {
93+
return _toBeRequired.toBeRequired;
94+
}
95+
});
96+
Object.defineProperty(exports, "toBeInvalid", {
97+
enumerable: true,
98+
get: function () {
99+
return _toBeInvalid.toBeInvalid;
100+
}
101+
});
102+
Object.defineProperty(exports, "toBeValid", {
103+
enumerable: true,
104+
get: function () {
105+
return _toBeInvalid.toBeValid;
106+
}
107+
});
108+
Object.defineProperty(exports, "toHaveValue", {
109+
enumerable: true,
110+
get: function () {
111+
return _toHaveValue.toHaveValue;
112+
}
113+
});
114+
Object.defineProperty(exports, "toBeChecked", {
115+
enumerable: true,
116+
get: function () {
117+
return _toBeChecked.toBeChecked;
118+
}
119+
});
120+
121+
var _toBeInTheDom = require("./to-be-in-the-dom");
122+
123+
var _toBeInTheDocument = require("./to-be-in-the-document");
124+
125+
var _toBeEmpty = require("./to-be-empty");
126+
127+
var _toContainElement = require("./to-contain-element");
128+
129+
var _toContainHtml = require("./to-contain-html");
130+
131+
var _toHaveTextContent = require("./to-have-text-content");
132+
133+
var _toHaveAttribute = require("./to-have-attribute");
134+
135+
var _toHaveClass = require("./to-have-class");
136+
137+
var _toHaveStyle = require("./to-have-style");
138+
139+
var _toHaveFocus = require("./to-have-focus");
140+
141+
var _toHaveFormValues = require("./to-have-form-values");
142+
143+
var _toBeVisible = require("./to-be-visible");
144+
145+
var _toBeDisabled = require("./to-be-disabled");
146+
147+
var _toBeRequired = require("./to-be-required");
148+
149+
var _toBeInvalid = require("./to-be-invalid");
150+
151+
var _toHaveValue = require("./to-have-value");
152+
153+
var _toBeChecked = require("./to-be-checked");

dist/to-be-checked.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.toBeChecked = toBeChecked;
7+
8+
var _jestMatcherUtils = require("jest-matcher-utils");
9+
10+
var _utils = require("./utils");
11+
12+
function toBeChecked(element) {
13+
(0, _utils.checkHtmlElement)(element, toBeChecked, this);
14+
15+
const isValidInput = () => {
16+
return element.tagName.toLowerCase() === 'input' && ['checkbox', 'radio'].includes(element.type);
17+
};
18+
19+
if (!isValidInput() && !(() => {
20+
return ['checkbox', 'radio'].includes(element.getAttribute('role')) && ['true', 'false'].includes(element.getAttribute('aria-checked'));
21+
})()) {
22+
return {
23+
pass: false,
24+
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'
25+
};
26+
}
27+
28+
const isChecked = () => {
29+
if (isValidInput()) return element.checked;
30+
return element.getAttribute('aria-checked') === 'true';
31+
};
32+
33+
return {
34+
pass: isChecked(),
35+
message: () => {
36+
const is = isChecked() ? 'is' : 'is not';
37+
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeChecked`, 'element', ''), '', `Received element ${is} checked:`, ` ${(0, _jestMatcherUtils.printReceived)(element.cloneNode(false))}`].join('\n');
38+
}
39+
};
40+
}

dist/to-be-disabled.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.toBeDisabled = toBeDisabled;
7+
exports.toBeEnabled = toBeEnabled;
8+
9+
var _jestMatcherUtils = require("jest-matcher-utils");
10+
11+
var _utils = require("./utils");
12+
13+
const FORM_TAGS = ['fieldset', 'input', 'select', 'optgroup', 'option', 'button', 'textarea'];
14+
/*
15+
* According to specification:
16+
* If <fieldset> is disabled, the form controls that are its descendants,
17+
* except descendants of its first optional <legend> element, are disabled
18+
*
19+
* https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
20+
*
21+
* This method tests whether element is first legend child of fieldset parent
22+
*/
23+
24+
function isFirstLegendChildOfFieldset(element, parent) {
25+
return (0, _utils.getTag)(element) === 'legend' && (0, _utils.getTag)(parent) === 'fieldset' && element.isSameNode(Array.from(parent.children).find(child => (0, _utils.getTag)(child) === 'legend'));
26+
}
27+
28+
function isElementDisabledByParent(element, parent) {
29+
return isElementDisabled(parent) && !isFirstLegendChildOfFieldset(element, parent);
30+
}
31+
32+
function isElementDisabled(element) {
33+
return FORM_TAGS.includes((0, _utils.getTag)(element)) && element.hasAttribute('disabled');
34+
}
35+
36+
function isAncestorDisabled(element) {
37+
const parent = element.parentElement;
38+
return Boolean(parent) && (isElementDisabledByParent(element, parent) || isAncestorDisabled(parent));
39+
}
40+
41+
function toBeDisabled(element) {
42+
(0, _utils.checkHtmlElement)(element, toBeDisabled, this);
43+
const isDisabled = isElementDisabled(element) || isAncestorDisabled(element);
44+
return {
45+
pass: isDisabled,
46+
message: () => {
47+
const is = isDisabled ? 'is' : 'is not';
48+
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeDisabled`, 'element', ''), '', `Received element ${is} disabled:`, ` ${(0, _jestMatcherUtils.printReceived)(element.cloneNode(false))}`].join('\n');
49+
}
50+
};
51+
}
52+
53+
function toBeEnabled(element) {
54+
(0, _utils.checkHtmlElement)(element, toBeEnabled, this);
55+
const isEnabled = !(isElementDisabled(element) || isAncestorDisabled(element));
56+
return {
57+
pass: isEnabled,
58+
message: () => {
59+
const is = isEnabled ? 'is' : 'is not';
60+
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeEnabled`, 'element', ''), '', `Received element ${is} enabled:`, ` ${(0, _jestMatcherUtils.printReceived)(element.cloneNode(false))}`].join('\n');
61+
}
62+
};
63+
}

dist/to-be-empty.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.toBeEmpty = toBeEmpty;
7+
8+
var _jestMatcherUtils = require("jest-matcher-utils");
9+
10+
var _utils = require("./utils");
11+
12+
function toBeEmpty(element) {
13+
(0, _utils.checkHtmlElement)(element, toBeEmpty, this);
14+
return {
15+
pass: element.innerHTML === '',
16+
message: () => {
17+
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeEmpty`, 'element', ''), '', 'Received:', ` ${(0, _jestMatcherUtils.printReceived)(element.innerHTML)}`].join('\n');
18+
}
19+
};
20+
}

dist/to-be-in-the-document.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.toBeInTheDocument = toBeInTheDocument;
7+
8+
var _jestMatcherUtils = require("jest-matcher-utils");
9+
10+
var _utils = require("./utils");
11+
12+
function toBeInTheDocument(element) {
13+
if (element !== null || !this.isNot) {
14+
(0, _utils.checkHtmlElement)(element, toBeInTheDocument, this);
15+
}
16+
17+
const pass = element === null ? false : element.ownerDocument.contains(element);
18+
19+
const errorFound = () => {
20+
return `expected document not to contain element, found ${(0, _jestMatcherUtils.stringify)(element.cloneNode(true))} instead`;
21+
};
22+
23+
const errorNotFound = () => {
24+
return `element could not be found in the document`;
25+
};
26+
27+
return {
28+
pass,
29+
message: () => {
30+
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeInTheDocument`, 'element', ''), '', (0, _jestMatcherUtils.RECEIVED_COLOR)(this.isNot ? errorFound() : errorNotFound())].join('\n');
31+
}
32+
};
33+
}

dist/to-be-in-the-dom.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.toBeInTheDOM = toBeInTheDOM;
7+
8+
var _jestMatcherUtils = require("jest-matcher-utils");
9+
10+
var _utils = require("./utils");
11+
12+
function toBeInTheDOM(element, container) {
13+
(0, _utils.deprecate)('toBeInTheDOM', 'Please use toBeInTheDocument for searching the entire document and toContainElement for searching a specific container.');
14+
15+
if (element) {
16+
(0, _utils.checkHtmlElement)(element, toBeInTheDOM, this);
17+
}
18+
19+
if (container) {
20+
(0, _utils.checkHtmlElement)(container, toBeInTheDOM, this);
21+
}
22+
23+
return {
24+
pass: container ? container.contains(element) : !!element,
25+
message: () => {
26+
return [(0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toBeInTheDOM`, 'element', ''), '', 'Received:', ` ${(0, _jestMatcherUtils.printReceived)(element ? element.cloneNode(false) : element)}`].join('\n');
27+
}
28+
};
29+
}

0 commit comments

Comments
 (0)