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.

How to test disappearance?

See original GitHub issue
  • cypress-testing-library version: 2.2.0
  • node version: 9.4.0
  • yarn version: 1.7.0

Relevant code or config

// I have a table with users, and I want to test user deletion
cy.getByTestId(`user-id-${userId}`).within(() => {
  cy.getByText('Remove').click();
});
cy.getByTestId(`user-id-${userId}`).should('not.exist');

What you did: I’ve tried to use cypress-testing-library custom commands with should(‘not.exist’) expectation.

What happened: The expectation failed, because cypress does not wait until the row/element disappeared.

On the other hand the following works as expected:

cy.getByTestId(`user-id-${invitee.userId}`).within(() => {
  cy.getByText('Remove').click();
});
cy.get(`[data-testid="user-id-${invitee.userId}"`).should('not.exist');

What would be the proper way to test element disappearance with custom commands?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
pr0dacommented, Oct 4, 2018

Sorry for the radio silence. I figured out that the following works as expected:

cy.getByTestId(`user-id-${userId}`).then(
  $el => cy.wrap($el).should('not.exist')
);

So we ended up overwriting cypress-testing-library commands by wrapping up subject:

['getByTestId', 'getByLabelText', 'getByText'].forEach(name => {
  Cypress.Commands.overwrite(name, (original, ...rest) =>
    original(...rest).then(subject => cy.wrap(subject, { log: false }))
  );
});

My plan was to investigate this further and eventually open a pr with a fix but it won`t happen at least for one month.

I hope this is helpful at least.

3reactions
krvajalcommented, Jan 31, 2019

I am having a similar problem. In my case, I have a button that changes its text like this “SAVE” => “SAVING” [duration unknown] => “SAVE” or (error case) “SAVE” => “SAVING” [duration unknown] => “COULD NOT SAVE”

The “SAVING” state can take some time to change. Is there a way to detect when the “SAVING” text is gone and then assert that the text changed to “SAVE”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appearance and Disappearance - Testing Library
Appearance and Disappearance. Sometimes you need to test that an element is present and then disappears or vice versa.
Read more >
Blocked Tear Ducts: Dye Disappearance Test - Topic Overview
A fluorescein dye disappearance test is used in children and adults to find out whether tears are draining normally from the eyes into...
Read more >
How to Diagnose the Missing Data Mechanism
The only true way to distinguish between MNAR and MAR is to measure some of that missing data. It's a common practice among...
Read more >
Fluorescein Dye Disappearance Test: A Reliable Test in Asses...
Fluorescein dye disappearance test (FDDT), first described by Jacobs 1 (named dye test) and then documented by Zappia and Milder, 2 measures the...
Read more >
Fluorescein dye disappearance
Related: FDDT, fluorescein dye disappearance test. Oculoplastics/Orbit. View Full Image · Image License and Citation Guidelines · Add to My Bookmarks.
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