How to override type or click?
See original GitHub issueCurrent behavior:
I have a custom command that interacts with the UI and waits for animations to complete called rerender
. I want to make sure to invoke rerender before and after clicking and typing. However, I’m not able to figure out the correct way to do this.
I’ve tried a couple things.
Cypress.Commands.overwrite("click", (originalFn, subject, ...args) => {
cy.rerender()
originalFn(subject, ...args)
cy.rerender()
})
Cypress.Commands.overwrite("click", (originalFn, subject, ...args) => {
cy.rerender()
cy.wrap(originalFn(subject, ...args))
cy.rerender()
})
Cypress.Commands.overwrite("click", (originalFn, subject, ...args) => {
cy.rerender()
.then(() => originalFn(subject, ...args))
.rerender()
})
Cypress.Commands.overwrite("click", (originalFn, subject, ...args) => {
cy.rerender().then(() => {
originalFn(subject, ...args).then(() => {
cy.rerender()
})
})
})
They all come up with some sort of error about a promise inside a promise or something…
CypressError: Timed out retrying: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
The command that returned the promise was:
> cy.type()
The cy command you invoked inside the promise was:
> cy.rerender()
Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.
Cypress will resolve your command with whatever the final Cypress command yields.
The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.
https://on.cypress.io/returning-promise-and-commands-in-another-command
Any ideas how overwriting these commands is supposed to work?
Versions
Cypress 3.1.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Overriding interface property type defined in Typescript d.ts file
I use a method that first filters the fields and then combines them. reference Exclude property from type interface A { x: string...
Read more >Override methods of a superclass | IntelliJ IDEA Documentation
On the Code menu, click Override methods Ctrl+O . Alternatively, you can right-click anywhere in the class file, then click Generate ...
Read more >How to Override a Rule or Monitor | Microsoft Learn
In the Monitors pane, expand an object type completely and then click a monitor. On the Operations console toolbar, click Overrides and then ......
Read more >Apply overrides to instances - Components - Figma Help Center
Reset overrides · Right-click on the instance in the canvas and select Reset Instance · Click the Reset All Overrides button in the...
Read more >User Type Override
To add additional ticket types, click into the white space in the box and the remaining Ticket Types will appear. Select each Ticket...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jennifer-shehane I argue that this is an issue with the documentation.
@ccorcos Has filed this in Gitter, but never got a reply.
I’m having exactly the same issue:
And all
.type()
fail with:Alright, I’ve made some progress. I think the problem has to do with the internal abstractions for these commands. The code below works. Now I can properly override those commands.
Still seems like a bad abstraction internally though. It means you can’t override these commands without substantial hacks.