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

Cypress passes a test when it finds 0 elements #8317

Closed
DaveClissold opened this issue Aug 19, 2020 · 3 comments
Closed

Cypress passes a test when it finds 0 elements #8317

DaveClissold opened this issue Aug 19, 2020 · 3 comments

Comments

@DaveClissold
Copy link

DaveClissold commented Aug 19, 2020

Current behavior:

When using .get() the test passes when it finds 0 elements, came about this after mistakingly writing a test and deleting some of the selectors, because tests failing due to issue #8189

Screenshot 2020-08-19 at 10 47 36

Desired behavior:

The test should fail

Test code to reproduce

Unfortunately cannot give a full repo to test but here is the test code and the html element in question that creates the dropdown menu

This test should fail

cy.get('[data-cy="Submenu"] > a').invoke('attr', 'href').should('contain','auto-curation')

Code being tested against

<div data-cy="Submenu">
  <div data-cy="List">
    <span>Users</span>
    <div data-cy="Item">
      <a href="/admin/users"><span>Manage Users</span></a>
    </div>
    <div data-cy="Item">
      <a href="/admin/security"><span>Security</span></a>
    </div>
    <div data-cy="Item">
      <a href="/admin/administrators"><span>Administrators</span></a>
    </div>
    <div data-cy="Item">
      <a href="/admin/users/profiles"><span>Profiles</span></a>
    </div>
    <span>Content</span>
    <div data-cy="Item">
      <a href="/admin/content"><span>Manage Content</span></a>
    </div>
    <div data-cy="Item">
      <a href="/admin/ugc"><span>UGC Configuration</span></a>
    </div>
    <div data-cy="Item">
      <a href="/admin/auto-curation"><span>Auto Curation</span></a>
    </div>
    <span>Features</span>
    <div data-cy="Item">
      <a href="/admin/notifications"><span>Notifications</span></a>
    </div>
    <div data-cy="Item">
      <a href="/admin/cpd"><span>CPD</span></a>
    </div>
    <span>Legacy</span>
    <div data-cy="Item">
      <a
        href="**externallink**"
        ><span>Admin Area</span></a
      >
    </div>
  </div>
</div>

Versions

Cypress: 4.12.1
Chrome 84 & Electron 80

Also when the test is written correctly it also fails not iterating through the elements to find the assertions, not sure if this is related

This test should pass

cy.get('[data-cy="Submenu"] [data-cy="List"] [data-cy="Item"] a').should('have.attr', 'href', '/admin/auto-curation')

Screenshot 2020-08-19 at 11 15 21

@DaveClissold DaveClissold changed the title Cypress passes a test which should fail Cypress passes a test when it finds 0 elements Aug 19, 2020
@jennifer-shehane
Copy link
Member

There may be some async situation where it does quickly find this element but then updates the UI to show 0 after there are no elements?

We'd need a reproducible example in order to track it down, but it is likely some kind of timing issue. With the code provided, I'm not able to reproduce it - the test correctly fails. Can you provide a repro?

For the second test - you are asserting that all 10 anchor links should have an href matching /admin/auto-curation - but only one of them would match that. You'll need to make your assertion more specific.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Aug 20, 2020
@DaveClissold
Copy link
Author

Ahh ok thanks @jennifer-shehane I'll have a look at adding in a longer wait of some sort or catch of a possible re-render and see if that catches it, unfortunately I cannot provide the repo or access to the platform I'm testing

For the second test ok that's my stupidity, sorry to have troubled you there, am still fairly new to testing, will dive into that a bit more.

Can I leave this open for a day or so and come back to you if i can find a way of reproducing this outside of the current platform?

@DaveClissold
Copy link
Author

I'm closing this as I cannot get permissions to open up a project or a repo for this to be tested on. Will look further into @jennifer-shehane thought about the re-render.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants