Skip to content

maxlength < 16 breaks .clear() #955

@KittyGiraudel

Description

@KittyGiraudel
  • Operating System: 10.12.6
  • Cypress Version: 1.1.1
  • Browser Version: n/a

Is this a Feature or Bug?

A bug.

Current behavior:

Calling .clear() on an input with a maxlength attribute smaller than 16 outputs odd characters in the field instead of clearing it.

Desired behavior:

Calling .clear() on an input with a maxlength attribute smaller than 16 clears the field.

How to reproduce:

Test code:

cy.get('input[maxlength]').clear()

Additional Info (images, stack traces, etc)

This bug was introduced in 1.1.1 with #930 as mentioned in this comment.

Calling .clear() seems to call .type() with {selectall}{del} as per the following snippet. This string is 16 characters long and takes into account the maxlength attribute (while it should not).

cy.now("type", $el, "{selectall}{del}", {

The changes introduced in 1.1.1 slice the characters to respect the maxlength attribute value, therefore slicing these tokens. This is why a maxlength from 1 to 15 causes this bug.

I guess not counting tokens in the characters count is probably the way to go. Pseudo code could look like:

const tokens = RegExp(Object.keys(keyStandardMap).join('|'), 'g')
chars.replace(tokens, '')

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions