-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
In a select element, the onChange event fires even when selecting the currently chosen option #19494
Labels
pkg/driver
This is due to an issue in the packages/driver directory
Comments
sainthkh
added
stage: ready for work
The issue is reproducible and in scope
pkg/driver
This is due to an issue in the packages/driver directory
labels
Jan 3, 2022
Confirmed with the code below: <html>
<head>
<meta charset='utf-8'>
<meta name='robots' content='noindex, nofollow'>
<title>Cypress onChange event bug</title>
</head>
<label>Choose an ice cream flavor:
<select class='ice-cream' name='ice-cream'>
<option value=''>Select One …</option>
<option value='chocolate'>Chocolate</option>
<option value='sardine'>Sardine</option>
<option value='vanilla'>Vanilla</option>
</select>
</label>
<div class='result'></div>
<script>
const selectElement = document.querySelector('.ice-cream');
let numOfTimesOnChangeFired = 0;
selectElement.addEventListener('change', (event) => {
const result = document.querySelector('.result');
result.textContent = `Number of times onChange event fired: ${++numOfTimesOnChangeFired}`;
});
</script>
</html> it('does not fire an onChange event when there is no change in a select element', () => {
cy.visit('fixtures/a.html')
cy.get('.ice-cream').select('Chocolate')
cy.get('.result').should('have.text', 'Number of times onChange event fired: 1')
// Select the option that is already selected - onChange event should not fire.
cy.get('.ice-cream').select('Chocolate')
cy.get('.result').should('have.text', 'Number of times onChange event fired: 1')
}) |
1 task
cypress-bot
bot
added
stage: needs review
The PR code is done & tested, needs review
stage: work in progress
and removed
stage: ready for work
The issue is reproducible and in scope
stage: needs review
The PR code is done & tested, needs review
stage: work in progress
labels
Jan 10, 2022
cypress-bot
bot
added
stage: backlog
and removed
stage: needs review
The PR code is done & tested, needs review
labels
Jan 19, 2022
cypress-bot
bot
added
stage: needs review
The PR code is done & tested, needs review
and removed
stage: backlog
labels
Feb 3, 2022
cypress-bot
bot
added
stage: pending release
and removed
stage: needs review
The PR code is done & tested, needs review
labels
Feb 9, 2022
The code for this is done in cypress-io/cypress#19623, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Current behavior
In a select element, the onChange event fires even when clicking on the option which is already selected. This behavior is not consistent with what actually happens in browsers (I tested this only on Chrome).
Desired behavior
In a select element, the onChange event should only fire when the value of the select element actually changes. When clicking on an option that is already selected, it should not fire.
Test code to reproduce
Here is a repo with a failing test. The code for the AUT can be found here.
Cypress Version
9.2.0
Other
No response
The text was updated successfully, but these errors were encountered: