@elastic/eui
Version:
Elastic UI Component Library
61 lines (56 loc) • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerEuiCypressMatchers = registerEuiCypressMatchers;
exports.setupEuiCypressMatchers = void 0;
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/// <reference types="cypress" />
function registerEuiCypressMatchers() {
var chai = window.chai;
if (chai && !chai.__euiMatchersRegistered) {
chai.use(function (_chai) {
_chai.Assertion.addProperty('euiDisabled', function () {
var element = this._obj[0] || this._obj;
var hasDisabledAttribute = element.hasAttribute('disabled');
var hasAriaDisabled = element.getAttribute('aria-disabled') === 'true';
var isDisabled = hasDisabledAttribute || hasAriaDisabled;
this.assert(isDisabled, 'expected element to be EUI disabled (= have `disabled` attribute or `aria-disabled="true"`)', 'expected element not to be EUI disabled (= not have `disabled` attribute or `aria-disabled="true"`)', true, isDisabled);
});
_chai.Assertion.addProperty('euiEnabled', function () {
var element = this._obj[0] || this._obj;
var hasDisabledAttribute = element.hasAttribute('disabled');
var hasAriaDisabled = element.getAttribute('aria-disabled') === 'true';
var isDisabled = hasDisabledAttribute || hasAriaDisabled;
this.assert(!isDisabled, 'expected element to be EUI enabled (= not have `disabled` attribute or `aria-disabled="true"`)', 'expected element not to be EUI enabled (= have `disabled` attribute or `aria-disabled="true"`)', false, isDisabled);
});
});
// Mark as registered to prevent double registration
chai.__euiMatchersRegistered = true;
}
}
// Register matchers when support file loads
var setupEuiCypressMatchers = exports.setupEuiCypressMatchers = function setupEuiCypressMatchers() {
if (typeof window !== 'undefined') {
// Try to register immediately
if (window.chai) {
registerEuiCypressMatchers();
} else {
// Wait for chai to be available
var pollForChai = function pollForChai() {
if (window.chai) {
registerEuiCypressMatchers();
} else {
setTimeout(pollForChai, 10);
}
};
pollForChai();
}
}
};