Skip to content

Proper way to overwrite cy.click() #14563

Answered by kjifs
kjifs asked this question in Questions and Help
Discussion options

You must be logged in to vote

In case anyone with a similar problem stumbles upon this in the future, I ended up going with this code:

Cypress.Commands.overwrite('click', (originalFn, subject, options) => {
	if (!options || (!options.force && options.verify !== false)) {
		cy.wrap(subject).should('not.have.attr', 'disabled').then(() => {
			return originalFn(subject,options);
		});
	} else {
		return originalFn(subject,options);
	}
});

verify: false does appear to be passed in on all internal calls to cy.click() so this accomplishes what I was looking for. Relying on this undocumented option isn't ideal, but I was unable to find a better solution that didn't require modifying our existing tests to add this assertion.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kjifs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant