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

Number inputs that are manually focused do not respect the caret position during cy.type() #7170

Closed
sdnts opened this issue Apr 29, 2020 · 3 comments · Fixed by #8515
Closed

Comments

@sdnts
Copy link

sdnts commented Apr 29, 2020

Current behavior:

I've set up a small repro app (link below) that has a button. When clicking on this button, an <input type="number" value="1" /> is created and manually focused (by calling focus() on it).

In my test, I click on this button, wait for the input to show up, and then attempt to type something into this input. Instead of appending typed characters to the end of the input (where the cursor is), Cypress appends them to the beginning of the input.

Desired behavior:

I expect the the typed character to be appended to the end of the input (where the cursor is), and the written test to pass.

Test code to reproduce

I've set up this repo that is a simplified version of my app and exhibits the issue:
https://github.com/madebysid/cypress-input-focus-issue

(I can fork https://github.com/cypress-io/cypress-test-tiny and set this up there instead if you prefer, but it seems very similar to what I have)

Versions

Cypress: 4.5.0
OS: macOS
Browser: Electron

Curiously enough, the test behaves as I expect (and passes) on Cypress 3.7.0. Cypress 3.8.0+ have this issue.

@jennifer-shehane
Copy link
Member

This behavior happening all the way back to 3.4.1, so was not introduced in a recent version.

Note: You never need to write ``should('exist'), this is asserted by default for any cy.get()` command.

To reproduce

index.html

<html>
<body>
  <button onclick="onClick()">Show input</button>
  <script>
    function onClick() {
      let input = document.createElement('input')
      // The type has to be a `number` for the test to fail
      input.type = 'number' 
      input.value = 1

      document.body.appendChild(input)

      // The input needs to be forcibly focused for the test to fail
      document.querySelector('input').focus() 
    }
  </script>
</body>
</html>

spec.js

it('can type in a number field correctly', () => {
  cy.visit('./index.html')
  cy.get('button').click()
  cy.get('input')
    .type('2')
    // fails
    .should('have.value', '12')
})

Screen Shot 2020-04-30 at 4 19 07 PM

@jennifer-shehane jennifer-shehane changed the title Number inputs that are manually focused are not type()ed in correctly Number inputs that are manually focused do not respect the caret position during cy.type() Apr 30, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Apr 30, 2020
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: ready for work The issue is reproducible and in scope labels Sep 8, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 11, 2020

The code for this is done in cypress-io/cypress#8515, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 15, 2020

Released in 5.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.2.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants