Custom command executes immediately and returns error 'not a function' #27355
Replies: 1 comment
-
I found the issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I added two very simple custom commands to cypress. These are just to demonstrate my issue.
When I put them in a test, those functions execute immediately and get a 'not a function' error.
If I put cy.wait() or cy.pause() at the top of the test case, those functions still execute immediately.
If I pull the functionality out of the custom commands and put them directly in the test case,
the functionality works fine.
it.only('should open status update page', () => {
cy.pause()
//Executes immediately and gets ERROR cy.VisitThis is not a function
cy.VisitThis('/app/order-status-update/#').url().should('include', 'order-status-update');
//cy.visit('/app/order-status-update/#').url().should('include', 'order-status-update'); //Works fine
Here are the custom commands
Cypress.Commands.add('GetThis', (selector) => {
cy.get(selector).should('exist');
});
Cypress.Commands.add('VisitThis', (url) => {
cy.visit(url);
});
Here are the command definitions
GetThis(selector: string): Chainable;
VisitThis(url: string): Chainable;
The question is, why are custom commands executing before they're being called?
Also, I've tried various Chainable types and those don't work either.
Any help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions