I am getting this error while overwriting the contains()
method.
Cannot read properties of undefined (reading 'hasPreviouslyLinkedCommand') in cypress
Here is the commands.js
file:
Cypress.Commands.add("clickOnLinks", (linkText) => {
cy.get("a").contains(linkText).click();
});
// overwriting contains()
// passing the same parameter for the contains method
Cypress.Commands.overwriteQuery(
"contains",
(originalFn, subject, filter, text, options = {}) => {
// determine if the filter argument was passed
if (typeof text === "object") {
options = text;
text = filter;
filter = undefined;
}
options.matchCase = false;
return originalFn(subject, filter, text, options);
}
);
And this is my test file:
describe("Custom command", () => {
it("overwriting the custom commands", () => {
cy.visit("https://magento.softwaretestingboard.com/");
// calling clickOnLinks command to click on the links
cy.clickOnLinks("RADIANT TEE").should("exist");
// verifying after performing click action
cy.get("span[class='base']").should("have.text", "Radiant Tee");
});
});
I'm using the latest version of cypress - 12.7.0
I have tried using this one as well but no luck -
Cypress.Commands.overwriteQuery
What am I missing? Can anyone help?