Skip to content

Commit

Permalink
feat(cdk/testing): add loaderForDocumentRoot method to `TestbedHarn…
Browse files Browse the repository at this point in the history
…essEnvironment`

This should have been included as part of angular#16709, but got overlooked
somehow
  • Loading branch information
mmalerba committed Sep 4, 2019
1 parent dd37ca5 commit d04ffcd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {UnitTestElement} from './unit-test-element';

/** A `HarnessEnvironment` implementation for Angular's Testbed. */
export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
constructor(rawRootElement: Element, private _fixture: ComponentFixture<unknown>) {
protected constructor(rawRootElement: Element, private _fixture: ComponentFixture<unknown>) {
super(rawRootElement);
}

Expand All @@ -23,6 +23,11 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
return new TestbedHarnessEnvironment(fixture.nativeElement, fixture);
}

/** Creates a `HarnessLoader` rooted at the document root element. */
static loaderForDocumentRoot(fixture: ComponentFixture<unknown>): HarnessLoader {
return new TestbedHarnessEnvironment(document.body, fixture);
}

/**
* Creates an instance of the given harness type, using the fixture's root element as the
* harness's host element. This method should be used when creating a harness for the root element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

import {BaseHarnessFilters} from '@angular/cdk-experimental/testing';
import {BaseHarnessFilters} from '@angular/cdk-experimental/testing';

export interface DialogHarnessFilters extends BaseHarnessFilters {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('MatDialogHarness', () => {

fixture = TestBed.createComponent(DialogHarnessTest);
fixture.detectChanges();
loader = new TestbedHarnessEnvironment(document.body, fixture);
loader = TestbedHarnessEnvironment.loaderForDocumentRoot(fixture);
dialogHarness = MatDialogHarness;
});

Expand Down

0 comments on commit d04ffcd

Please sign in to comment.