Cypress: .type() negative number into input not working

Created on 19 Jul 2018  路  8Comments  路  Source: cypress-io/cypress

Current behavior:

When typing negative number into input with type "number" set, minus is ignored and possitive number is typed instead.

used method: cy.type()

numbertypebug

Desired behavior:

Type negative number.

Steps to reproduce:

html

Versions

Cypress: 3.0.2
Windows 10
Chrome 67

pkdriver bug

All 8 comments

Hi, @equistx ,
This issue should be fixed in an upcoming 3.0.3 release, via this PR #2016

In version 3.3.0 this bug is still on.
Schermata 2019-05-22 alle 15 29 12

The tests are:

    it("Should be max 10", () => {
        cy.get(".count").should("be.lessThan", "11");
    });
    it("Should be min 1", () => {
        cy.get("#count").should("be.greaterThan", "0");
    });

In version 3.3.0 this bug is still on.

@Fenopiu your screenshot and test code don't indicate this has anything to do with failing to type negative numbers

@Fenopiu You likely want to assert on the 'value' inside of the span, not the span itself. Something like.

it("Should be max 10", () => {
  cy.get(".count").invoke('text').then((text) => {
    expect(text).to.be.lessThan(11);
  })
})

in v 3.4.0 i can confirm this bug still appears.

See:
0000000333

@TheBestPessimist

in v 3.4.0 i can confirm this bug still appears.

0--? That's zero?
0---12345? What?

Please show your Cypress test code or a simple case of a negative number failing

Here's the relevant piece of code:

  cy.get('.form-field-MovementQty')
    .find('input')
    .type('{selectall}')
    .type(`-222`)
    .type('{enter}');

Here's a gif showing that instead of -222, cypress types 222 along with the request sent to the backend:
cypress minus bug

Here's the body of the frontend request: [{"op":"replace","path":"MovementQty","value":"222"}], where it should have been "value": "-222".

Here's the html of that element:

<div class="form-group row  form-field-MovementQty">
    <div class="form-control-label col-sm-3" title="Menge eines bewegten Produktes.">Bewegungs-Menge</div>
    <div class="col-sm-9 ">
        <div class="input-body-container"><span></span>
            <div class="input-block input-secondary pulse-off"><input autocomplete="new-password" class="input-field js-input-field" placeholder="none" tabindex="0" title="222" type="number" min="0" step="1" value="222"></div>
        </div>
    </div>
</div>

I have also tried the alternative

  cy.get('.form-field-MovementQty')
    .find('input')
    .type('{selectall}')
    .type(-222) // instead of `-222`
    .type('{enter}');

but that didnt help either.


Here's a gif of me typing a negative number in the same field, along with the request sent to the backend:
e

@TheBestPessimist Thanks for this. I see the issue, we don't take into account that the input has a selection. You can workaround this by doing .clear() before .type() for now. I'll open an issue to fix this

Edit: see open issue here #4767

Was this page helpful?
0 / 5 - 0 ratings