UNPKG

enzyme-page-object

Version:

A library to help write enzyme tests using the page-object pattern

132 lines (117 loc) 3.7 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var FoundElement = function () { function FoundElement(element) { _classCallCheck(this, FoundElement); this.element = element; } _createClass(FoundElement, [{ key: 'click', value: function click(options) { this.element.simulate('click', options); } }, { key: 'change', value: function change(value) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var checkbox = this.element.prop('checked'); var newValue = checkbox !== undefined ? { checked: value } : { value: value }; var mergedOptions = _extends({}, options, { target: _extends({}, options.target, newValue) }); this.element.simulate('change', mergedOptions); } }, { key: 'debug', value: function debug() { return this.element.debug(); } }, { key: 'filter', value: function filter(selector) { this.element = this.element.filter(selector); return this; } }, { key: 'find', value: function find(selector) { this.element = this.element.find(selector); return this; } }, { key: 'first', value: function first() { return this.element.first(); } }, { key: 'instance', value: function instance() { return this.element.instance(); } }, { key: 'last', value: function last() { return this.element.last(); } }, { key: 'map', value: function map(callback) { var wrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; return this.element.map(function (node) { if (wrap) { return new FoundElement(callback(node)); } else { return callback(node); } }); } }, { key: 'prop', value: function prop(key) { return this.element.prop(key); } }, { key: 'props', value: function props() { return this.element.props(); } }, { key: 'setContext', value: function setContext(context) { this.element.setContext(context); return this; } }, { key: 'state', value: function state(key) { return this.element.state(key); } }, { key: 'text', value: function text() { return this.element.text(); } }, { key: 'type', value: function type() { return this.element.type(); } }, { key: 'update', value: function update() { this.element.update(); } }, { key: 'length', get: function get() { return this.element.length; } }]); return FoundElement; }(); exports.default = FoundElement;