Skip to content

Commit

Permalink
Add type for section parent property. (#4369)
Browse files Browse the repository at this point in the history
* Add type for section parent property.

* Fix tests.
  • Loading branch information
garg3133 authored Feb 12, 2025
1 parent 97a94df commit 993e6c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions types/page-object.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ export type EnhancedSectionInstance<
Commands = {},
Elements = {},
Sections extends Record<string, PageObjectSection> = {},
Props = {}
> = EnhancedPageObjectSections<Commands, Elements, Sections, Props> &
Props = {},
Parent = unknown
> = EnhancedPageObjectSections<Commands, Elements, Sections, Props, Parent> &
Commands &
ElementCommands &
ChromiumClientCommands &
Expand Down Expand Up @@ -202,7 +203,8 @@ export interface EnhancedPageObjectSections<
Commands = {},
Elements = {},
Sections extends Record<string, PageObjectSection> = {},
Props = {}
Props = {},
Parent = unknown
> extends EnhancedPageObjectSharedFields<
Commands,
Elements,
Expand All @@ -229,6 +231,11 @@ export interface EnhancedPageObjectSections<
* 'css selector'
*/
locateStrategy: LocateStrategy;

/**
* Parent of the section.
*/
parent: Parent;
}

interface EnhancedPageObjectSharedFields<
Expand Down Expand Up @@ -258,7 +265,8 @@ interface EnhancedPageObjectSharedFields<
Required<MergeObjectsArray<Sections[Key]['commands']>>,
Required<MergeObjectsArray<Sections[Key]['elements']>>,
Required<Sections[Key]['sections']>,
Required<Sections[Key]['props']>
Required<Sections[Key]['props']>,
this
>;
};

Expand Down
5 changes: 5 additions & 0 deletions types/tests/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ const testPage = {
appSection.expect.element('@myAccount').to.be.visible;
appSection.expect.element('@youtube').to.be.visible;

// test for parent property
expectType<typeof menuSection>(appSection.parent);
expectType<GooglePage>(appSection.parent.parent);
expectError(appSection.parent.parent.parent);

const youtubeElement = appSection.elements.youtube;
expectNotType<any>(youtubeElement);

Expand Down

0 comments on commit 993e6c2

Please sign in to comment.