Reputation: 327
In a .ts file I create a test to try and access a custom created command from command.js, createInbox
function is underlined with red with the following message : Property 'createInbox' does not exist on type 'cy & EventEmitter
it.only('dsdsds', () => {
cy.createInbox().then((inbox) => {
console.log(inbox);
// { id: '...', emailAddress: '...' }
});
})
My command.js file look like this
const { MailSlurp } = require("mailslurp-client");
const mailslurp = new MailSlurp(Cypress.env("mailSlurpApiKey"));
Cypress.Commands.add("createInbox", () => {
return mailslurp.createInbox();
});
Cypress.Commands.add("waitForLatestEmail", (inboxId) => {
return mailslurp.waitForLatestEmail(inboxId);
});
I understand that I have to rename command.js to ts, however when I do that all custom commands is underlined with red with the following error : Argument of type '"waitForLatestEmail"' is not assignable to parameter of type 'keyof Chainable
How could I fix this?
Upvotes: 4
Views: 6447
Reputation: 198
I had this problem aswell! My solution: I had my *.d.ts files located inside the cypress/support folder, right next to the *.ts files with all the custom commands. Moving those outside(!) the "support"-folder and into another one called "definitionFiles" (for example) worked beautifully!
Upvotes: 4
Reputation: 327
Solved by adding custom chainable interface to support folder
declare namespace Cypress {
interface Chainable {
createInbox(): Chainable<any>;
waitForLatestEmail(inboxId: number): Chainable<any>;
}
}
Upvotes: 3