This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mitigate console spam during component tests * Add hook to switch between query and command form of cy.component * Implement cy.component as a query * Refactor command declarations and options into central locations.
- Loading branch information
Showing
9 changed files
with
230 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Component, ComponentOptions, Text, isText } from '../../interfaces'; | ||
|
||
export function describePseudoSelector(component: Component, text?: Text) { | ||
if (!text) return component.query; | ||
else if (text instanceof RegExp) | ||
return `${component.query}:component-text(${text})`; | ||
else return `${component.query}:component-text('${text}')`; | ||
} | ||
|
||
// Extract the options passed to the command, if any. | ||
export function getOptions(rest: any[]) { | ||
switch (rest.length) { | ||
case 1: | ||
if (rest[0] && !isText(rest[0])) return rest[0]; | ||
break; | ||
default: | ||
return rest[1]; | ||
} | ||
} | ||
|
||
// Extract the text paramter passed to the command, if any. | ||
export const getText = (rest: any[]) => (isText(rest[0]) ? rest[0] : undefined); | ||
|
||
// Return a full hash of options w/ default values for anything not overrridden. | ||
export function normalizeOptions(rest: any[]): ComponentOptions { | ||
// Deliberate copy of defaults every time; Cypress destructively modifies it. | ||
const defl = { | ||
all: false, | ||
log: true, | ||
timeout: Cypress.config().defaultCommandTimeout, | ||
}; | ||
return getOptions(rest) || defl; | ||
} | ||
|
||
export function mapAll($collection: JQuery, callback: ($el: JQuery) => JQuery) { | ||
return $collection.map(function (this: HTMLElement) { | ||
const $element = Cypress.$(this); | ||
return callback($element).get()[0]; | ||
}); | ||
} |
Oops, something went wrong.