question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getBy* with .should('not.exist')

See original GitHub issue

The behavior of cypress-testing-library’s getBy queries is a bit different than the cypress built-in .get() method: the built-in will retry should('not.exist') until it times out, but the getBy queries timeout on the query. One workaround is to change to getBy to queryBy, but this requires a little bit of extra dom-testing-library knowledge that can confuse people coming from Cypress, and still doesn’t retry.

Alternative

// This doesn't work
cy.getByTestId('my-item').should('not.exist');

// This works for verifying an element isn't present *right now*
cy.queryByTestId('my-item').should('be.null');

// This should retry but does not
cy.queryByTestId('my-item').should('not.exist');

Idea

It might make sense for queryBy* to actually be aliased to getBy* in the cypress context?

EDIT: actually the .should() chain should really trigger a retry of the parent command. Maybe custom commands don’t hook into .should correctly?

Related to #23, https://github.com/cypress-io/cypress/issues/3109

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
alexkrolickcommented, Jan 10, 2019

I’m thinking Cypress should support hooking into the retry mechanism for custom commands. Filed an issue to discuss: https://github.com/cypress-io/cypress/issues/3109

0reactions
kentcdoddscommented, Jan 10, 2019

I’d be fine if anyone wants to try to make that happen. Then we can switch over to a built-in API when it becomes available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you test for the non-existence of an element using jest ...
From DOM Testing-library Docs - Appearance and Disappearance. Asserting elements are not present. The standard getBy methods throw an error ...
Read more >
About Queries | Testing Library
Single Elements. getBy... : Returns the matching node for a query, and throw a descriptive error if no elements match or if more...
Read more >
Testing Library - Queries - DEV Community ‍ ‍
This article explains the three types of queries ("getBy", "findBy", "queryBy") and how to ... Asserting an element should not be present.
Read more >
Guide to testing in React - my software development blog
getBy vs findBy vs queryBy; The act() function; Waiting for async actions ... You can check if an element does not exist by...
Read more >
contains - Cypress Documentation
getCookies().contains('_key') // Errors, 'getCookies' does not yield DOM ... .contains() yields the new DOM element it found. .contains() is a query, ...
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