This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/cypress/support/commands.js

18 lines
635 B
JavaScript

/**
* getAttached(selector)
* getAttached(selectorFn)
*
* Waits until the selector finds an attached element, then yields it (wrapped).
* selectorFn, if provided, is passed $(document). Don't use cy methods inside selectorFn.
*
* Source: https://github.com/cypress-io/cypress/issues/5743#issuecomment-650421731
*/
Cypress.Commands.add('getAttached', selector => {
const getElement = typeof selector === 'function' ? selector : $d => $d.find(selector);
let $el = null;
return cy.document().should($d => {
$el = getElement(Cypress.$($d));
expect(Cypress.dom.isDetached($el)).to.be.false;
}).then(() => cy.wrap($el));
});