.type() will not accept an empty string

See original GitHub issue

Current behavior:

CypressError: cy.type() cannot accept an empty String. You need to actually type something.

Desired behavior:

An empty string is a valid an often necessary test on an input field. The type method should support this.

Steps to reproduce: (app code and test code)

cy.get('input element').type('')

Versions

Cypress: 3.1.5 MacOs Mojave 10.14.3 Chrome 72

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
StJohn3Dcommented, May 1, 2019

Can we re-open this? I’m trying to write dynamic tests that cleanup after themselves. Take the value of input A and store it for later. Type something, click save and assert on reload that it’s there.

Now in the cleanup phase I want to write back whatever value was there before. This is where cy.type is breaking my tests if the original value was an empty string.

I have to add an if statement that basically checks to see if the original value was an empty string, and if it was, then don’t call cy.type. This isn’t ideal, cy.type feels like any string value should be a valid argument - even an empty string.

9reactions
jennifer-shehanecommented, May 2, 2019

If you want to set the value of an input as an empty string, you can do this programatically. A person cannot type an empty string, so this will not be supported in .type().

To do this programmatically:

cy.get('input').invoke('val', '')
Read more comments on GitHub >

github_iconTop Results From Across the Web

type() will not accept an empty string cypress - Stack Overflow
Just focus and blur indeed: it('Should display You must enter a value if user does not type anything', () => { cy.get('#username') .focus()...
Read more >
21.2 Validating Null and Empty Strings
An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is...
Read more >
DFDL empty strings causing a CTDU4132E error and APARs ...
There is currently no solution for cases where the element is a blank string and the data type is non-numeric. Finding an applicable...
Read more >
Handle empty strings when migrating from Oracle to PostgreSQL
During code migration from your Oracle to PostgreSQL database, adding NULLIF is required only for character varying data types. This is not ......
Read more >
String field type doesn't consider empty string as empty value
but $entity->validate() would accept empty string as a value, because the the field has an item (with value empty string) ?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found