Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An Its() function cannot access index of zero. #6216

Closed
Misxy opened this issue Jan 22, 2020 · 4 comments · Fixed by #6234 · May be fixed by rangle/test-automation#29
Closed

An Its() function cannot access index of zero. #6216

Misxy opened this issue Jan 22, 2020 · 4 comments · Fixed by #6234 · May be fixed by rangle/test-automation#29
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: bug

Comments

@Misxy
Copy link

Misxy commented Jan 22, 2020

Current behavior:

From the tutorial on the official website (https://docs.cypress.io/api/commands/its.html) when I have used with an array following the example I have found an issue of the function. The function could access indices from indices one to last indices of the array. However, when I have used the indices zero with the function the compiler have an error.

Desired behavior:

The function have been access by indices zero to the last indices of the example array.

Test code to reproduce

cy.wrap(['Wai Yan', 'Yu']).its(1).should('eq', 'Yu') // true
cy.wrap(['Wai Yan', 'Yu']).its(0).should('eq', 'Yu') // CypressError: cy.its() expects the propertyName argument to have a value.

Versions

Cypress version (Installed via npm) : 3.8.2
Os: Windows 10

@jennifer-shehane
Copy link
Member

Yes, this is a bug. Good catch.

Being able to use indices for .its() was introduced in 3.7.0 in this PR: #5755, but then the .its() command had some more changes made in 3.8.0 in this PR: #5519

It seems that the 0 property for index is being evaluated as falsey and throwing an error as if there is no 1st argument given to the command.

The error in logic was added here: https://github.com/cypress-io/cypress/pull/5519/files#diff-5b34517122a03995ae6793f0a8d18797R182 where it does a simple if (!str) check, which will evaluate as falsey without considering that 0 is a valid expected argument. cc @gabbersepp

This code below needs to be fixed to address this and a test that uses .its(0) needs to be added.

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/connectors.coffee#L184:L184

This actually appears to have also been a bug in 3.7.0 release, as it also does not return the 0 index (although does not error), so there may be some more code necessary to make this work. cc @flotwig

Reproducible Code

it('failure', () => {
  cy.wrap(['Wai Yan', 'Yu']).its(1).should('eq', 'Yu') 
  cy.wrap(['Wai Yan', 'Yu']).its(0).should('eq', 'Wai Yan') 
})

3.7.0

Screen Shot 2020-01-22 at 6 22 57 PM

3.8.0

Screen Shot 2020-01-22 at 6 23 59 PM

@jennifer-shehane jennifer-shehane added the pkg/driver This is due to an issue in the packages/driver directory label Jan 22, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jan 22, 2020
@jennifer-shehane jennifer-shehane added the good first issue Good for newcomers label Jan 22, 2020
@datner
Copy link
Contributor

datner commented Jan 24, 2020

I am currently doing this one, the project is a bit overwhelming for me so I might get this wrong so please be patient with me :) (also writing coffeescript on the fly so thats cool).

I'm actually done but the pre-commit hook is breaking on me, so, I'm dealing with that

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress stage: needs review The PR code is done & tested, needs review labels Jan 24, 2020
flotwig pushed a commit that referenced this issue Jan 27, 2020
* add support and tests for 0 as path for its()

* Fix typo in README of driver

* export prop checking to a helper function

* add tests for .invoke() cases
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 27, 2020

The code for this is done in cypress-io/cypress#6234, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@flotwig
Copy link
Contributor

flotwig commented Feb 6, 2020

Released in 4.0.0.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
4 participants