Skip to content

Commit

Permalink
e9f873a feat(testing): export useful properties from componentFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Dec 3, 2015
1 parent de9e604 commit 788d500
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions BUILD_INFO
@@ -1,2 +1,2 @@
Thu Dec 3 00:21:46 UTC 2015
25a2d7b5db7806e1b6b3ce0b5380cf94253bbe4c
Thu Dec 3 00:22:40 UTC 2015
e9f873a365a627525e81fefee2a5bd335ca54067
19 changes: 19 additions & 0 deletions lib/src/testing/test_component_builder.dart
Expand Up @@ -24,8 +24,25 @@ import "package:angular2/src/core/debug/debug_element.dart"
* Fixture for debugging and testing a component.
*/
abstract class ComponentFixture {
/**
* The DebugElement associated with the root element of this component.
*/
DebugElement debugElement;
/**
* The instance of the root component class.
*/
dynamic componentInstance;
/**
* The native element at the root of the component.
*/
dynamic nativeElement;
/**
* Trigger a change detection cycle for the component.
*/
void detectChanges();
/**
* Trigger component destruction.
*/
void destroy();
}

Expand All @@ -38,6 +55,8 @@ class ComponentFixture_ extends ComponentFixture {
/* super call moved to initializer */;
this.debugElement =
new DebugElement_(internalView((componentRef.hostView as ViewRef)), 0);
this.componentInstance = this.debugElement.componentInstance;
this.nativeElement = this.debugElement.nativeElement;
this._componentParentView =
internalView((componentRef.hostView as ViewRef));
this._componentRef = componentRef;
Expand Down
26 changes: 10 additions & 16 deletions test/testing/test_component_builder_spec.dart
Expand Up @@ -106,8 +106,7 @@ main() {
(TestComponentBuilder tcb, async) {
tcb.createAsync(ChildComp).then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText("Original Child");
expect(componentFixture.nativeElement).toHaveText("Original Child");
async.done();
});
}));
Expand All @@ -117,12 +116,10 @@ main() {
(TestComponentBuilder tcb, async) {
tcb.createAsync(MyIfComp).then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText("MyIf()");
componentFixture.debugElement.componentInstance.showMore = true;
expect(componentFixture.nativeElement).toHaveText("MyIf()");
componentFixture.componentInstance.showMore = true;
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText("MyIf(More)");
expect(componentFixture.nativeElement).toHaveText("MyIf(More)");
async.done();
});
}));
Expand All @@ -135,8 +132,7 @@ main() {
.createAsync(MockChildComp)
.then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText("Mock");
expect(componentFixture.nativeElement).toHaveText("Mock");
async.done();
});
}));
Expand All @@ -152,8 +148,7 @@ main() {
.createAsync(ChildComp)
.then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText("Modified Child");
expect(componentFixture.nativeElement).toHaveText("Modified Child");
async.done();
});
}));
Expand All @@ -166,8 +161,7 @@ main() {
.createAsync(ParentComp)
.then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText("Parent(Mock)");
expect(componentFixture.nativeElement).toHaveText("Parent(Mock)");
async.done();
});
}));
Expand All @@ -182,7 +176,7 @@ main() {
.createAsync(ParentComp)
.then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
expect(componentFixture.nativeElement)
.toHaveText("Parent(Original Child(ChildChild Mock))");
async.done();
});
Expand All @@ -195,7 +189,7 @@ main() {
provide(FancyService, useClass: MockFancyService)
]).createAsync(TestBindingsComp).then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
expect(componentFixture.nativeElement)
.toHaveText("injected value: mocked out value");
async.done();
});
Expand All @@ -208,7 +202,7 @@ main() {
provide(FancyService, useClass: MockFancyService)
]).createAsync(TestViewBindingsComp).then((componentFixture) {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
expect(componentFixture.nativeElement)
.toHaveText("injected value: mocked out value");
async.done();
});
Expand Down

0 comments on commit 788d500

Please sign in to comment.