Skip to content

Commit

Permalink
feat: get-component-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoBorzi committed Jan 20, 2025
1 parent 5f1575b commit 922564b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"printWidth": 120,
"singleQuote": true
}
15 changes: 13 additions & 2 deletions libs/ngx-page-object-model/src/lib/page-object-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ export abstract class PageObjectModel<ComponentType> {
/**
* Given a CSS selector, returns an array of all matching DebugHtmlElement items.
*/
getAllDebugElementsByCss<HTMLElementType extends HTMLElement = HTMLElement>(cssSelector: string): DebugHtmlElement<HTMLElementType>[] {
getAllDebugElementsByCss<HTMLElementType extends HTMLElement = HTMLElement>(
cssSelector: string,
): DebugHtmlElement<HTMLElementType>[] {
return this.fixture.debugElement.queryAll(By.css(cssSelector));
}

/**
* Given a data-testid, returns an array of all matching DebugHtmlElement items.
*/
getAllDebugElementsByTestId<HTMLElementType extends HTMLElement = HTMLElement>(testId: string): DebugHtmlElement<HTMLElementType>[] {
getAllDebugElementsByTestId<HTMLElementType extends HTMLElement = HTMLElement>(
testId: string,
): DebugHtmlElement<HTMLElementType>[] {
return this.getAllDebugElementsByCss(this.getSelectorByTestId(testId));
}

Expand All @@ -86,6 +90,13 @@ export abstract class PageObjectModel<ComponentType> {
return this.fixture.debugElement.queryAll(By.directive(directive));
}

/**
* Given a component type, returns the component instance.
*/
getComponentInstance<T>(componentType: Type<T>, assert = true): T {
return this.getDebugElementByDirective(componentType, assert).componentInstance as T;
}

/**
* Given an array of data-testid, returns the matching nested DebugHtmlElement item.
*/
Expand Down

0 comments on commit 922564b

Please sign in to comment.