From e72443888729a5c1535f7d743c64edac5982b1c3 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Tue, 27 Sep 2022 12:03:09 -0700 Subject: [PATCH 1/7] fix: Explain error thrown when cypress commands in .should() callback --- content/api/commands/should.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/content/api/commands/should.md b/content/api/commands/should.md index 7f9cff17e3..3d4afc5949 100644 --- a/content/api/commands/should.md +++ b/content/api/commands/should.md @@ -172,6 +172,24 @@ Be sure _not_ to include any code that has side effects in your callback function. The callback function will be retried over and over again until no assertions within it throw. +You cannot invoke Cypress commands inside of a `.should()` callback function. +Use cypress commands before or after `.should()` instead. + +** Correct Usage** + +```javascript +cy.get('p').should(($p) => { ... }).log() +``` + +** Incorrect Usage** + +```javascript +cy.get('p').should(($p) => { + cy.log($p) + ... +}) +``` + #### Verify length, content, and classes from multiple `

` ```html @@ -467,10 +485,11 @@ following: ## History -| Version | Changes | -| --------------------------------------------- | --------------------------------- | -| [0.11.4](/guides/references/changelog#0-11-4) | Allows callback function argument | -| [< 0.3.3](/guides/references/changelog#0-3-3) | `.should()` command added | +| Version | Changes | +| --------------------------------------------- | ----------------------------------------------- | +| [11.0.0](/guides/references/changelog#11-0-0) | Throw error if Cypress command used in callback | +| [0.11.4](/guides/references/changelog#0-11-4) | Allows callback function argument | +| [< 0.3.3](/guides/references/changelog#0-3-3) | `.should()` command added | ## See also From cf18ccfbbd18ed77370bf27487830d6ac3f65091 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Tue, 27 Sep 2022 12:20:00 -0700 Subject: [PATCH 2/7] Improve layout of previous changes and provide second example of how to fix --- content/api/commands/should.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/content/api/commands/should.md b/content/api/commands/should.md index 3d4afc5949..92ffacaabe 100644 --- a/content/api/commands/should.md +++ b/content/api/commands/should.md @@ -175,12 +175,6 @@ assertions within it throw. You cannot invoke Cypress commands inside of a `.should()` callback function. Use cypress commands before or after `.should()` instead. -** Correct Usage** - -```javascript -cy.get('p').should(($p) => { ... }).log() -``` - ** Incorrect Usage** ```javascript @@ -190,6 +184,19 @@ cy.get('p').should(($p) => { }) ``` +** Correct Usage** + +```javascript +cy.get('p').should(($p) => { ... }).log() + +// or + +cy.get('p').then(($p) => { + ... + cy.log($p) + }) +``` + #### Verify length, content, and classes from multiple `

` ```html From 9ec797e1b4616208197fa1651629300ad1f2f6c2 Mon Sep 17 00:00:00 2001 From: Blue F Date: Tue, 27 Sep 2022 17:07:32 -0700 Subject: [PATCH 3/7] Update content/api/commands/should.md Co-authored-by: Rachel --- content/api/commands/should.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/api/commands/should.md b/content/api/commands/should.md index 92ffacaabe..f2746d0140 100644 --- a/content/api/commands/should.md +++ b/content/api/commands/should.md @@ -173,7 +173,7 @@ function. The callback function will be retried over and over again until no assertions within it throw. You cannot invoke Cypress commands inside of a `.should()` callback function. -Use cypress commands before or after `.should()` instead. +Use Cypress commands before or after `.should()` instead. ** Incorrect Usage** From eba68dd9985bface99bb149e4a59b19850f92de7 Mon Sep 17 00:00:00 2001 From: Blue F Date: Wed, 28 Sep 2022 11:50:04 -0700 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Zach Bloomquist --- content/api/commands/should.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/api/commands/should.md b/content/api/commands/should.md index f2746d0140..698b3e512e 100644 --- a/content/api/commands/should.md +++ b/content/api/commands/should.md @@ -180,21 +180,23 @@ Use Cypress commands before or after `.should()` instead. ```javascript cy.get('p').should(($p) => { cy.log($p) - ... + // ... }) ``` ** Correct Usage** ```javascript -cy.get('p').should(($p) => { ... }).log() +cy.get('p').should(($p) => { + // ... +}).log() // or cy.get('p').then(($p) => { - ... + // ... cy.log($p) - }) +}) ``` #### Verify length, content, and classes from multiple `

` From 2c673580921073585ca61f2612897222ebb35872 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Tue, 11 Oct 2022 13:51:13 -0700 Subject: [PATCH 5/7] Run prettier --- .../end-to-end-testing/working-with-graphql.md | 5 +++-- content/guides/guides/test-retries.md | 1 + content/guides/tooling/typescript-support.md | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/content/guides/end-to-end-testing/working-with-graphql.md b/content/guides/end-to-end-testing/working-with-graphql.md index 3054892d87..da04582a81 100644 --- a/content/guides/end-to-end-testing/working-with-graphql.md +++ b/content/guides/end-to-end-testing/working-with-graphql.md @@ -140,8 +140,9 @@ context('Tests', () => { req.reply((res) => { // Modify the response body directly res.body.data.launches.hasMore = false - res.body.data.launches.launches = - res.body.data.launches.launches.slice(5) + res.body.data.launches.launches = res.body.data.launches.launches.slice( + 5 + ) }) } }) diff --git a/content/guides/guides/test-retries.md b/content/guides/guides/test-retries.md index 7dcf27696b..910f5759aa 100644 --- a/content/guides/guides/test-retries.md +++ b/content/guides/guides/test-retries.md @@ -246,6 +246,7 @@ describe('User Login', () => { 'user-login-errors (attempt 3).png' // screenshot filename on 3rd failed attempt 'user-login-errors (failed) (attempt 3).png' + ``` ## Videos diff --git a/content/guides/tooling/typescript-support.md b/content/guides/tooling/typescript-support.md index e324cd93a6..71f66d21f2 100644 --- a/content/guides/tooling/typescript-support.md +++ b/content/guides/tooling/typescript-support.md @@ -183,13 +183,13 @@ declare global { ```typescript // cypress/support/index.ts -Cypress.Commands.add( - 'typeRandomWords', - { prevSubject: 'element' }, - (subject /* :JQuery */, count = 3, options?) => { - return cy.wrap(subject).type(generateRandomWords(count), options) - } -) +Cypress.Commands.add('typeRandomWords', { prevSubject: 'element' }, ( + subject /* :JQuery */, + count = 3, + options? +) => { + return cy.wrap(subject).type(generateRandomWords(count), options) +}) ``` #### Overwriting child or dual commands From 155ecdd65321be45912dbc24597c2977d8eeaa28 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Tue, 11 Oct 2022 14:01:26 -0700 Subject: [PATCH 6/7] Run prettier again...? --- content/api/commands/should.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/content/api/commands/should.md b/content/api/commands/should.md index 698b3e512e..764e63a96f 100644 --- a/content/api/commands/should.md +++ b/content/api/commands/should.md @@ -187,9 +187,11 @@ cy.get('p').should(($p) => { ** Correct Usage** ```javascript -cy.get('p').should(($p) => { - // ... -}).log() +cy.get('p') + .should(($p) => { + // ... + }) + .log() // or From 9d38766f81a765cae3aaed285e01b022bfb40631 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Tue, 11 Oct 2022 14:45:06 -0700 Subject: [PATCH 7/7] One more prettier run... :/ --- .../end-to-end-testing/working-with-graphql.md | 5 ++--- content/guides/guides/test-retries.md | 1 - content/guides/tooling/typescript-support.md | 14 +++++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/content/guides/end-to-end-testing/working-with-graphql.md b/content/guides/end-to-end-testing/working-with-graphql.md index da04582a81..3054892d87 100644 --- a/content/guides/end-to-end-testing/working-with-graphql.md +++ b/content/guides/end-to-end-testing/working-with-graphql.md @@ -140,9 +140,8 @@ context('Tests', () => { req.reply((res) => { // Modify the response body directly res.body.data.launches.hasMore = false - res.body.data.launches.launches = res.body.data.launches.launches.slice( - 5 - ) + res.body.data.launches.launches = + res.body.data.launches.launches.slice(5) }) } }) diff --git a/content/guides/guides/test-retries.md b/content/guides/guides/test-retries.md index 910f5759aa..7dcf27696b 100644 --- a/content/guides/guides/test-retries.md +++ b/content/guides/guides/test-retries.md @@ -246,7 +246,6 @@ describe('User Login', () => { 'user-login-errors (attempt 3).png' // screenshot filename on 3rd failed attempt 'user-login-errors (failed) (attempt 3).png' - ``` ## Videos diff --git a/content/guides/tooling/typescript-support.md b/content/guides/tooling/typescript-support.md index 71f66d21f2..e324cd93a6 100644 --- a/content/guides/tooling/typescript-support.md +++ b/content/guides/tooling/typescript-support.md @@ -183,13 +183,13 @@ declare global { ```typescript // cypress/support/index.ts -Cypress.Commands.add('typeRandomWords', { prevSubject: 'element' }, ( - subject /* :JQuery */, - count = 3, - options? -) => { - return cy.wrap(subject).type(generateRandomWords(count), options) -}) +Cypress.Commands.add( + 'typeRandomWords', + { prevSubject: 'element' }, + (subject /* :JQuery */, count = 3, options?) => { + return cy.wrap(subject).type(generateRandomWords(count), options) + } +) ``` #### Overwriting child or dual commands