Skip to content

Commit

Permalink
Merge pull request #26 from DesignByOnyx/25-fix-shadow-find
Browse files Browse the repository at this point in the history
fix(shadowFind): fix issues with retry-ability and $.find semantics
  • Loading branch information
abramenal authored Dec 25, 2019
2 parents 9a3bb80 + 5311a8d commit 0a619e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
14 changes: 11 additions & 3 deletions src/commands/shadowFind/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ export default function shadowFind(subject, selector, options = {}) {
validateOptions(options, DEFAULT_COMMAND_OPTIONS);

const elGetter = () => {
const currentElement = subject[0].shadowRoot || subject[0];
const found = currentElement.querySelectorAll(selector);
const found = Cypress.$(selector, subject);

return found;
if (found.length) {
return found;
}

return Array.from(subject).reduce((result, sub) => {
if (sub.shadowRoot) {
return result.add(selector, sub.shadowRoot);
}
return result;
}, Cypress.$([]));
};

return resolveValue(elGetter, options).then(foundElements => {
Expand Down
16 changes: 0 additions & 16 deletions src/validators/validateSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,4 @@ export default selector => {
if (!selector || typeof selector !== 'string') {
throw new InternalError(ERR_TYPES.INVALID_SELECTOR);
}

/*
* Matches any spaces not inside ""
* e.g. `input[placeholder="First A Name"]` will not be matched
* however `div input[placeholder="Text"]` will find the whitespace
*/
const illegalSpaceBeforeRegex = /(?<!".+)(\s)/g;
const illegalSpaceAfterRegex = /(\s)(?!.+")/g;

if (!!selector.match(illegalSpaceBeforeRegex) || !!selector.match(illegalSpaceAfterRegex)) {
throw new InternalError(ERR_TYPES.INVALID_SELECTOR_NO_MULTI);
}

if (selector.indexOf('@') !== -1) {
throw new InternalError(ERR_TYPES.INVALID_SELECTOR_NO_ALIAS);
}
};

0 comments on commit 0a619e1

Please sign in to comment.