Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.within() now throws an error if given more than one subject #4898

Merged
merged 3 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions content/_changelogs/12.0.0.md
Expand Up @@ -11,6 +11,11 @@ _Released MM/DD/YYYY_
- Cypress now throws an error if commands are invoked from inside a `.should()`
callback. This previously resulted in unusual and undefined behavior; it is
now explicitly an error.
- The `.within()` command now throws an error if given more than one DOM element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BlueWinds Can you add a migration guide entry on how to resolve this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added migration guide.

BlueWinds marked this conversation as resolved.
Show resolved Hide resolved
as a subject. This is done for consistency - in older versions, some commands
inside a `.within()` block would respect all passed in elements, while others
silently discarded subjects beyond the first, and `.screenshot()` would throw
an error.
- `Cookies.defaults` and `Cookies.preserveOnce` have been removed. Please update
to use [`cy.session()`](/api/commands/session) to preserve session details
between tests. Addresses
Expand Down
12 changes: 7 additions & 5 deletions content/api/commands/within.md
Expand Up @@ -179,7 +179,8 @@ cy.get('form').within(($form) => {

### Requirements [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Chains-of-Commands)

<List><li>`.within()` requires being chained off a previous command.</li></List>
- `.within()` requires being chained off a previous command that yields exactly
one DOM element.

### Assertions [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Assertions)

Expand Down Expand Up @@ -211,10 +212,11 @@ outputs the following:

## History

| Version | Changes |
| --------------------------------------------- | ------------------------------------------------------- |
| [< 0.3.3](/guides/references/changelog#0-3-3) | `.within()` command added |
| [5.4.0](/guides/references/changelog#5-4-0) | fixed the yielded value to always be the parent element |
| Version | Changes |
| --------------------------------------------- | -------------------------------------------------------------------------------- |
| [12.0.0](/guides/references/changelog#12-0-0) | `.within()` now throws an error when given more than one element as the subject. |
| [5.4.0](/guides/references/changelog#5-4-0) | fixed the yielded value to always be the parent element |
| [< 0.3.3](/guides/references/changelog#0-3-3) | `.within()` command added |

## See also

Expand Down