@helpscout/cyan
Version:
Cypress-like Testing for React + JSDOM
103 lines (81 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _assert = require("../utils/assert.utils");
var _is = require("../utils/is.utils");
function contains(content) {
var _this = this;
return (0, _assert.assert)(function () {
return _this.getNode().innerHTML.includes(content);
});
}
function exists() {
return !!this.getNodes().length;
}
function hasAttribute(attr) {
var _this2 = this;
return (0, _assert.assert)(function () {
var node = _this2.getNode();
var attrValue = node[attr];
var propValue = node.getAttribute(attr);
return (0, _is.isDefined)(attrValue) || (0, _is.isDefined)(propValue);
});
}
function hasClassName(className) {
var _this3 = this;
return (0, _assert.assert)(function () {
return _this3.getNode().classList.contains(className);
});
}
function isTagName(tagName) {
var _this4 = this;
return (0, _assert.assert)(function () {
return _this4.getNode().tagName.toLowerCase() === tagName.toLowerCase();
});
}
function isChecked() {
var _this5 = this;
return (0, _assert.assert)(function () {
return !!_this5.getNode().checked;
});
}
function isDisabled() {
var _this6 = this;
return (0, _assert.assert)(function () {
return !!_this6.getNode().disabled;
});
}
function matches(selector) {
var _this7 = this;
return (0, _assert.assert)(function () {
return _this7.getNode().matches(selector);
});
}
function toContain(content) {
console.warn('Use .contains() instead to .toContain()');
return this.contains(content);
}
function toExist() {
console.warn('Use .contains() instead to .toExist()');
return this.exists();
}
var commands = {
contains: contains,
exists: exists,
hasAttribute: hasAttribute,
hasAttr: hasAttribute,
hasClassName: hasClassName,
hasClass: hasClassName,
isTagName: isTagName,
isTag: isTagName,
isChecked: isChecked,
isDisabled: isDisabled,
matches: matches,
is: matches,
toContain: toContain,
toExist: toExist
};
var _default = commands;
exports.default = _default;