Skip to content

Commit

Permalink
fix(commands.type): Fix the .type command on an input of type number
Browse files Browse the repository at this point in the history
Fix edge case introduced into cypress-io#6033 about typing invalid number

Fixes cypress-io#6055
  • Loading branch information
termcaps committed Jan 8, 2020
1 parent 639ba32 commit 91a6246
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/driver/src/cy/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ const shouldUpdateValue = (el: HTMLElement, key: KeyDetails, options) => {
debug('skipping inserting value since number input would be invalid', key.text, potentialValue)
// when typing in a number input, only certain whitelisted chars will insert text
if (!key.text.match(isValidNumberInputChar)) {
options.prevVal = ''
// https://github.com/cypress-io/cypress/issues/6055
// Should not remove old valid values when a new one is not a valid number char, just dismiss it with return

return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,13 @@ describe('src/cy/commands/actions/type', () => {
.should('have.value', '-123.12')
})

// https://github.com/cypress-io/cypress/issues/6055
it('can type negative numbers and dismiss invalid characters', () => {
cy.get('#number-without-value')
.type('-a42')
.should('have.value', '-42')
})

it('can type {del}', () => {
cy.get('#number-with-value')
.type('{selectAll}{del}')
Expand Down

0 comments on commit 91a6246

Please sign in to comment.