Skip to content

Commit

Permalink
Merge pull request #11 from hammzj/dev/update-base-types
Browse files Browse the repository at this point in the history
Dev/update base types
  • Loading branch information
hammzj authored Apr 16, 2024
2 parents 93d91c9 + 80f71b8 commit 33f7328
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 312 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hammzj/cypress-page-object",
"version": "2.0.2",
"version": "2.0.3",
"description": "A set of template classes and guides to help with developing component and page objects in Cypress.",
"author": "Zachary Hamm <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -38,6 +38,7 @@
"test:cypress:run:e2e": "cypress run --e2e --browser electron"
},
"dependencies": {
"@types/node": "^20.12.7",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/element.collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export default abstract class ElementCollection {
protected _baseContainerFn: BaseContainerFunction;
protected _scopedIndex?: number;
protected metadata: Partial<IMetadata>;
public elements: Elements = {
protected elements: Elements = {
container: () => this.container(),
};
public components?: NestedComponents = {};
protected components?: NestedComponents = {};

/**
* @param baseContainerFn {function} The base container function returns the container of the element.
Expand Down
6 changes: 3 additions & 3 deletions src/page.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InsufficientPathVariablesError extends Error {
*/
export default class PageObject extends ElementCollection {
static #PATH_REPLACEMENT_REGEX = /(?<pathVariable>:\w+)/g;
protected metadata: IPageMetadata;
public metadata: IPageMetadata;

/**
* @example new PageObject(); //Index page
Expand Down Expand Up @@ -85,8 +85,8 @@ export default class PageObject extends ElementCollection {
return pathInputs ? this.#customPathUrl(...pathInputs) : this.#urlObject().toString();
}

visit(...pathInputs: string[]): void {
cy.visit(this.url(...pathInputs));
visit(pathInputs: string[], opts?: Partial<Cypress.VisitOptions>): void {
cy.visit(this.url(...pathInputs), opts);
}

assertIsOnPage(...pathInputs: string[]): void {
Expand Down
6 changes: 4 additions & 2 deletions src/types/element.collection.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import ElementCollection from "../element.collection";

export type BaseContainerFunction = () => Cypress.Chainable<Cypress.JQueryWithSelector>;
export type ElementSelectorFunction = (...params: any) => Cypress.Chainable<Cypress.JQueryWithSelector>;

export type BaseContainerFunction = ElementSelectorFunction;

export type Elements = {
[key: string]: (...params: any) => Cypress.Chainable<Cypress.JQueryWithSelector>;
[key: string]: ElementSelectorFunction;
};

export type ComponentObjectFunction = (instance: ElementCollection | any) => void;
Expand Down
Loading

0 comments on commit 33f7328

Please sign in to comment.