feat(testing): export useful properties from componentFixture

The component fixture returned from the test component builder
now exports `nativeElement` and `componentInstance` members
directly. They are also still available on the `debugElement`.

See #5385
This commit is contained in:
Julie Ralph
2015-11-30 12:49:22 -08:00
committed by Jeremy Elbourn
parent 25a2d7b5db
commit e9f873a365
2 changed files with 32 additions and 10 deletions
@@ -27,9 +27,29 @@ import {DebugElement, DebugElement_} from 'angular2/src/core/debug/debug_element
* Fixture for debugging and testing a component.
*/
export abstract class ComponentFixture {
/**
* The DebugElement associated with the root element of this component.
*/
debugElement: DebugElement;
/**
* The instance of the root component class.
*/
componentInstance: any;
/**
* The native element at the root of the component.
*/
nativeElement: any;
/**
* Trigger a change detection cycle for the component.
*/
abstract detectChanges(): void;
/**
* Trigger component destruction.
*/
abstract destroy(): void;
}
@@ -43,6 +63,8 @@ export class ComponentFixture_ extends ComponentFixture {
constructor(componentRef: ComponentRef) {
super();
this.debugElement = new DebugElement_(internalView(<ViewRef>componentRef.hostView), 0);
this.componentInstance = this.debugElement.componentInstance;
this.nativeElement = this.debugElement.nativeElement;
this._componentParentView = internalView(<ViewRef>componentRef.hostView);
this._componentRef = componentRef;
}