Cypress: Overriding type

Created on 17 Nov 2017  路  4Comments  路  Source: cypress-io/cypress

  • Operating System: MacOS Sierra 10.12.6
  • Cypress Version: 1.0.3
  • Browser Version: Chrome 62

Is this a Feature or Bug?

Bug

Current behavior:

It throws an error whenever I'm doing

Desired behavior:

Allow me to set a custom delay when typing. Preferably at a cypress.json configuration level.

How to reproduce:

Cypress.Commands.overwrite("type", (originalFn, string) => originalFn(string, { delay: 1 }))
cy.get('foo').type('bar')

Test code:

cy.get('foo').type('bar')

Additional Info (images, stack traces, etc)

screen shot 2017-11-17 at 18 51 49

question

Most helpful comment

Thank you! This works:

Cypress.Commands.overwrite(
    "type",
    (originalFn, subject, string, options) => originalFn(
        subject,
        string,
        Object.assign({}, options, { delay: 1 )
    )
)

All 4 comments

This isn't a bug. You've overriding a child command which yields you the current subject as the 2nd argument. The cy.type() must know what element it's typing into. You basically provided it a string as the element, and an object as to what to type.

Cypress.Commands.overwrite("type", (originalFn, subject, string, options) => ...

Cypress.Commands.overwrite(
    "type",
    (originalFn, subject, string, options) => originalFn(
        string,
        Object.assign({}, options, {delay: 1})
    )
)

cy.get('input[name="mainPhoneNo"]').type('07070707070')

now throws
screen shot 2017-11-17 at 19 04 33

Because you're not actually passing subject to type. Type must be called with the subject as its first argument.

Thank you! This works:

Cypress.Commands.overwrite(
    "type",
    (originalFn, subject, string, options) => originalFn(
        subject,
        string,
        Object.assign({}, options, { delay: 1 )
    )
)
Was this page helpful?
0 / 5 - 0 ratings