I would like to extend Mocha's describe
with forUsers
function that would create multiple describe. One for each user.
Original description definition:
interface IContextDefinition {
(description: string, callback: (this: ISuiteCallbackContext) => void): ISuite;
only(description: string, callback: (this: ISuiteCallbackContext) => void): ISuite;
skip(description: string, callback: (this: ISuiteCallbackContext) => void): void;
timeout(ms: number): void;
}
My extension:
declare namespace Mocha {
interface IContextDefinition {
forUsers(description: string, users: userType[], callback: (this: ISuiteCallbackContext, user: Cypress.userType) => void): void
only: {
(description: string, callback: (this: ISuiteCallbackContext) => void): ISuite
forUsers(description: string, users: userType[], callback: (this: ISuiteCallbackContext, user: userType) => void): void
}
skip: {
(description: string, callback: (this: ISuiteCallbackContext) => void): ISuite
forUsers(description: string, users: userType[], callback: (this: ISuiteCallbackContext, user: userType) => void): void
}
}
}
But I am getting this error:
Subsequent property declarations must have the same type. Property 'only' must be of type '(description: string, callback: (this: ISuiteCallbackContext) => void) => ISuite', but here has type '{ (description: string, callback: (this: ISuiteCallbackContext) => void): ISuite; forUsers(description: string, users: userType[], callback: (this: ISuiteCallbackContext, user: userType) => void): void; }'.
That only
, can be only of type original type, even if the new type includes the old one.