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

element selector: ":last" vs ":last-child" #753

Open
xmquan opened this issue Oct 8, 2023 · 6 comments
Open

element selector: ":last" vs ":last-child" #753

xmquan opened this issue Oct 8, 2023 · 6 comments

Comments

@xmquan
Copy link

xmquan commented Oct 8, 2023

should be changed to .find('tbody tr:last-child') to get the last element. The :last-child is accepted in CSS while not :last .

@MikeMcC399
Copy link
Collaborator

@zeromquan

Interesting find! The one line of code is not the only place where :last is used.

Documentation

The reason that :last works is as follows:

The Cypress find command documentation says:

The querying behavior of this command matches exactly how
.find() works in jQuery.

jQuery > Category: Selectors includes the :last Selector.

HOWEVER, this positional selector is deprecated!

Deprecation

The jQuery > :last Selector was deprecated in jQuery 3.4.0 released on April 10, 2019. See section "Deprecating positional selectors and the sunset of Sizzle", where it says:

jQuery 3.4.0 is deprecating :first, :last, :eq, :even, :odd, :lt, :gt, and :nth.

Suggestion

Review and revise all use of the deprecated jQuery positional selectors such as :first and :last, both in this repository and in the Cypress documentation repository.

@xmquan
Copy link
Author

xmquan commented Oct 9, 2023

for the positional selector, .first() .last() are more Cypressic way.

@MikeMcC399

This comment was marked as outdated.

@MikeMcC399

This comment was marked as outdated.

@MikeMcC399
Copy link
Collaborator

@alexsch01

Thanks for spotting that Cypress >= 13.13.1 is using jquery@3.4.1! I have hidden my post, which you quoted, as outdated.

The suggestion in #753 (comment) to update the usage is still valid and the tests continue to work with the current Cypress 13.15.2 despite the deprecation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants