Comments (7)
I'm a little late to the party. I introduced some changes to the way these Cypress Custom commands work. Is this still an issue in 5.2.1
?
I know for sure the original error shouldn't happen, because the .then
was removed in #108 (lines here: https://github.com/testing-library/cypress-testing-library/pull/108/files#diff-1fdf421c05c1140f6d71444ea2b27638L75-L77)
In fact, since moving to 5.0.0 I'm seeing these failures when I wasn't before. Unhelpfully, I now no longer which command actually failed.
Hopefully this is no longer an issue. That's what #108 sought to address - better debugging of failures.
My recommendation is to change all query*
to find*
. query*
commands do not retry until success like find*
queries do and like all other built-in Cypress commands. They will pass or fail almost instantly. They also can be a little flaky because technically in @testing-library/dom
query*
commands are synchronous and all Cypress commands are asynchronous. query*
queries try to mimic synchronous behavior by executing asap and not retrying. If your application is a bit slower for whatever reason, query
could fail.
The changes introduced in 5.2.1
could fail where previously they passed, but not because the previous logic was correct, but because query*
never failed if it didn't find what you were looking for. If query*
failed to find an element, it would return an empty object. So the following would never fail before but does now:
cy.queryByText('Does not exist').should('exist')
from cypress-testing-library.
I remember this piece of code, I think I wrote it. At that time I never used "should not exist" and I wonder why does it not take care of the timeout inside Cypress. The timeout was originally meant to wait for the element to exist.
from cypress-testing-library.
Nope, at the time of writing there was no timeout ef22f87#diff-1fdf421c05c1140f6d71444ea2b27638R20
The timeout appears later ec3b712#diff-1fdf421c05c1140f6d71444ea2b27638R43
CC @npeterkamps
from cypress-testing-library.
Removing the timeout option on the call to then()
will cause an issue when specifying a timeout value larger than the default command timeout.
I think the original problem happens when waitForElement
takes longer than 100ms to queue and execute the timeout code, but I can't figure out a way to avoid or recover from that.
Adding more than 100ms might make the issue less frequent, but it is not a sure way to avoid it :(
from cypress-testing-library.
Is this still an issue after the changes to retries in #78 ?
from cypress-testing-library.
Still an issue.
In fact, since moving to 5.0.0 I'm seeing these failures when I wasn't before. Unhelpfully, I now no longer which command actually failed.
CypressError: cy.then() timed out after waiting '4000ms'.
Your callback function returned a promise which never resolved.
The callback function was:
thenArgs => {
const getValue = () => {
const value = commandImpl(thenArgs.document);
const result = Cypress.$(value); // Overriding the selector of the jquery object because it's displayed in the long message of .should('exist') failure message
// Hopefully it makes it clearer, because I find the normal response of "Expected to find element '', but never found it" confusing
result.selector = `${queryName}(${queryArgument(args)})`;
if (result.length > 0) {
consoleProps.yielded = result.toArray();
}
return result;
};
const resolveValue = () => {
// retry calling "getValue" until following assertions pass or this command times out
return Cypress.Promise.try(getValue).then(value => {
return cy.verifyUpcomingAssertions(value, waitOptions, {
onRetry: resolveValue
});
});
};
if (queryRegex.test(queryName)) {
// For get* queries, do not retry
return getValue();
}
return resolveValue().then(subject => {
// Remove the error that occurred because it is irrelevant now
if (consoleProps.error) {
delete consoleProps.error;
}
return subject;
});
from cypress-testing-library.
I think we're safe to close this now. If this is still a problem for anyone please open a new issue. Thanks!
from cypress-testing-library.
Related Issues (20)
- Add Cypress 12 as an acceptable peer dependency HOT 2
- Enable to click to input number -webkit-inner-spin-button HOT 1
- Cypress test errors after upgraing to 9.0.0 and using testIsolation: false HOT 10
- findAllByRole and findByRole don't chain correctly HOT 2
- get/query variants don't exist HOT 3
- Testing library throws uncaught error HOT 24
- @testing-library/cypress causes non-cypress tests to fail HOT 1
- any `find*` command fails when is first to run in a test context HOT 6
- Dependency problem on @testing-library/dom between @testing-library/react and cypress-testing-library HOT 1
- Update @testing-library/dom HOT 1
- Conflicting peer dependency with new Cypress release 13.0.0 HOT 2
- should not exist does not work with findByRole
- Configuring testIdAttribute does not work HOT 1
- Doesn't work with Cypress 13.4.0 due to `addQuery` usage HOT 3
- npx cypress open fails on ubuntu 20.03 for missing GLIBCXX_3.4.29 HOT 1
- Unable to install Cypress version 13
- Property 'findByTestId' does not exist on type 'cy & CyEventEmitter' - only in .cy.tsx (component testing) files HOT 1
- Can't resolve 'process/browser.js'
- cy.findByText doesn't work on Cypress 13.6.4 in some situations HOT 2
- `findByRole` with `name` option does not consider element title when element contains text.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress-testing-library.