From f75d1b086ae9f06f0ee66c8bfcfbb9f44640446a Mon Sep 17 00:00:00 2001 From: Paul Jaffre Date: Wed, 5 Apr 2023 17:59:53 -0400 Subject: [PATCH 1/4] add callout about error --- docs/api/cypress-api/custom-commands.mdx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/api/cypress-api/custom-commands.mdx b/docs/api/cypress-api/custom-commands.mdx index 558501d186..242d69d84a 100644 --- a/docs/api/cypress-api/custom-commands.mdx +++ b/docs/api/cypress-api/custom-commands.mdx @@ -315,6 +315,17 @@ Log? Read more about [Command Logging](#Command-Logging). ::: +:::caution + +Note that `Cypress.Commands.add()` will throw an error when trying to add a +custom command with the same name as an existing built-in Cypress command or +reserved internal function. In order to override the behavior of an existing +command, `Cypress.Commands.overwrite()` should be used instead. For more +information, read the section +[Overwrite Existing Commands](#Overwrite-Existing-Commands). + +::: + ### Child Commands Child commands are always chained off of a **parent** command, or another From 292eb01e63164b340a4e63840c862f5178f2e965 Mon Sep 17 00:00:00 2001 From: Paul Jaffre Date: Thu, 6 Apr 2023 13:18:55 -0400 Subject: [PATCH 2/4] add PR feedback --- docs/api/cypress-api/custom-commands.mdx | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/docs/api/cypress-api/custom-commands.mdx b/docs/api/cypress-api/custom-commands.mdx index 242d69d84a..539c188f39 100644 --- a/docs/api/cypress-api/custom-commands.mdx +++ b/docs/api/cypress-api/custom-commands.mdx @@ -25,6 +25,15 @@ in the ::: +:::caution + +There are two API available for adding custom commands: + +- [`Cypress.Commands.add()`](#Syntax) - use to add a custom command to use when writing tests +- [`Cypress.Command.overwrite()`](#Overwrite-Existing-Commands) - use to override an existing built-in Cypress command or reserved internal function. **Caution:** this overrides it for Cypress as well and could impact how Cypress behaves. + +::: + ## Syntax ```javascript @@ -315,17 +324,6 @@ Log? Read more about [Command Logging](#Command-Logging). ::: -:::caution - -Note that `Cypress.Commands.add()` will throw an error when trying to add a -custom command with the same name as an existing built-in Cypress command or -reserved internal function. In order to override the behavior of an existing -command, `Cypress.Commands.overwrite()` should be used instead. For more -information, read the section -[Overwrite Existing Commands](#Overwrite-Existing-Commands). - -::: - ### Child Commands Child commands are always chained off of a **parent** command, or another @@ -849,8 +847,7 @@ couple commands. Don't do things like: -- **** - `cy.clickButton(selector)` +- **** `cy.clickButton(selector)` - **** `.shouldBeVisible()` This first custom command is wrapping `cy.get(selector).click()`. Going down From be80e80082f6472736e54a1e71b458604162f8c4 Mon Sep 17 00:00:00 2001 From: Paul Jaffre Date: Thu, 6 Apr 2023 13:23:09 -0400 Subject: [PATCH 3/4] lint --- docs/api/cypress-api/custom-commands.mdx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/api/cypress-api/custom-commands.mdx b/docs/api/cypress-api/custom-commands.mdx index 539c188f39..2d006776ea 100644 --- a/docs/api/cypress-api/custom-commands.mdx +++ b/docs/api/cypress-api/custom-commands.mdx @@ -29,8 +29,12 @@ in the There are two API available for adding custom commands: -- [`Cypress.Commands.add()`](#Syntax) - use to add a custom command to use when writing tests -- [`Cypress.Command.overwrite()`](#Overwrite-Existing-Commands) - use to override an existing built-in Cypress command or reserved internal function. **Caution:** this overrides it for Cypress as well and could impact how Cypress behaves. +- [`Cypress.Commands.add()`](#Syntax) - use to add a custom command to use when + writing tests +- [`Cypress.Command.overwrite()`](#Overwrite-Existing-Commands) - use to + override an existing built-in Cypress command or reserved internal function. + **Caution:** this overrides it for Cypress as well and could impact how + Cypress behaves. ::: @@ -847,7 +851,8 @@ couple commands. Don't do things like: -- **** `cy.clickButton(selector)` +- **** + `cy.clickButton(selector)` - **** `.shouldBeVisible()` This first custom command is wrapping `cy.get(selector).click()`. Going down From f404b5e30e9a60f86dd63f100a3135bc8c14ebc0 Mon Sep 17 00:00:00 2001 From: Paul Jaffre Date: Thu, 6 Apr 2023 14:10:19 -0400 Subject: [PATCH 4/4] elevate note and treat as text --- docs/api/cypress-api/custom-commands.mdx | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/docs/api/cypress-api/custom-commands.mdx b/docs/api/cypress-api/custom-commands.mdx index 2d006776ea..efa4ad23d3 100644 --- a/docs/api/cypress-api/custom-commands.mdx +++ b/docs/api/cypress-api/custom-commands.mdx @@ -7,6 +7,15 @@ Cypress comes with its own API for creating custom commands and overwriting existing commands. The built in Cypress commands use the very same API that's defined below. +There are two API available for adding custom commands: + +- [`Cypress.Commands.add()`](#Syntax) - use to add a custom command to use when + writing tests +- [`Cypress.Command.overwrite()`](#Overwrite-Existing-Commands) - use to + override an existing built-in Cypress command or reserved internal function. + **Caution:** this overrides it for Cypress as well and could impact how + Cypress behaves. + :::info If you want your method to have builtin @@ -25,19 +34,6 @@ in the ::: -:::caution - -There are two API available for adding custom commands: - -- [`Cypress.Commands.add()`](#Syntax) - use to add a custom command to use when - writing tests -- [`Cypress.Command.overwrite()`](#Overwrite-Existing-Commands) - use to - override an existing built-in Cypress command or reserved internal function. - **Caution:** this overrides it for Cypress as well and could impact how - Cypress behaves. - -::: - ## Syntax ```javascript