@helpscout/cyan
Version:
Cypress-like Testing for React + JSDOM
79 lines (58 loc) • 1.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _invariant = _interopRequireDefault(require("invariant"));
var _commands = _interopRequireDefault(require("../commands"));
var _selector = require("../utils/selector.utils");
var _command = require("../utils/command.utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Cyan =
/*#__PURE__*/
function () {
function Cyan(el) {
this.el = [];
this.length = 0;
if (el) {
this.get(el);
}
} // QuerySelectors
var _proto = Cyan.prototype;
_proto.get = function get(selector) {
this.el = (0, _selector.get)(selector);
this.length = this.el.length;
return this;
};
_proto.getByCy = function getByCy(selector) {
this.get("[data-cy=" + selector + "]");
return this;
};
_proto.getByText = function getByText(text) {
this.get((0, _selector.getByText)(text, this.getNode()));
return this;
} // (Base) Getters
;
_proto.getEl = function getEl() {
return this.el;
};
_proto.getNodes = function getNodes() {
return this.getEl();
};
_proto.getNode = function getNode() {
return this.getEl()[0];
};
_proto.__getNode = function __getNode(fn, selector) {
var el = this.getNode();
if (selector) {
(0, _invariant.default)(el, "Base selector does not exist to ." + fn + "('" + selector + "')");
} else {
(0, _invariant.default)(el, "Base selector does not exist for .(" + fn + ")");
}
return el;
};
return Cyan;
}();
(0, _command.withCommands)(_commands.default)(Cyan);
var _default = Cyan;
exports.default = _default;