After update 9.0.0 in Cypress I have the following error
Argument type string is not assignable to parameter type keyof Chainable... Type string is not assignable to type "and" | "as" | "blur" | "check" | "children" | "clear" | "clearCookie" | "clearCookies" | "clearLocalStorage" | "click" | "clock" | ... Type string is not assignable to type "intercept" which affect all my custom commands
Could someone help me? My custom command
Beginning with version 9.0.0, You are now forced to declare your custom commands. See the changelog for 9.0.0 (6th bullet point under breaking changes) and see the specific information about custom commands now being typed based on the declared custom chainable here.
Also, see this recipe on how to add custom commands and declare them properly.
For your custom command, add this file cypress/support/index.d.ts
with the following code:
/// <reference types="cypress" />
declare namespace Cypress {
interface Chainable<Subject = any> {
/**
* Custom command to ... add your description here
* @example cy.clickOnMyJourneyInCandidateCabinet()
*/
clickOnMyJourneyInCandidateCabinet(): Chainable<null>;
}
}
in support/index.d.ts
declare namespace Cypress {
interface Chainable<Subject = string> {
preventSubmit(form: string): Chainable<Element>;
}
}
in support/commnad.js
Cypress.Commands.add("preventSubmit", (form) => {
cy.get(form).then((form$) => {
form$.on("submit", (e) => {
e.preventDefault();
});
});
cy.log(`prevent default submit to '${form}'`);
});
in specs/test.js
describe("MyTest", () => {
...
it("Test 1", () => {
...
cy.preventSubmit("form");
cy.get("form").submit();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With