import Chainable = Cypress.Chainable; import Chainer = Cypress.Chainer; export type ComponentType = { new(p: Chainable, assertion?: (s: JQuery) => void): Component, defaultSelector: string }; export class BaseComponent { static defaultSelector = ''; static count = 0; element: Chainable; id: number; assertion?: (s: JQuery) => void; constructor(element: Chainable, assertion?: (s: JQuery) => void) { this.id = BaseComponent.count++; this.element = element.as('component' + this.id); this.assertion = assertion; } get(): Chainable { if (this.assertion) { return cy.get('@component' + this.id, {log: false}).should(this.assertion); } return cy.get('@component' + this.id, {log: false}); } should: Chainer = (arg, ...others) => { return cy.get('@component' + this.id, {log: false}).should(arg, ...others); }; }