Skip to content

Commit 39a6f85

Browse files
committed
test(TestComponentBuilder): add tests for overriding child component's directive
1 parent 3dfb7d4 commit 39a6f85

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

modules/angular2/src/mock/directive_resolver_mock.ts

Whitespace-only changes.

modules/angular2/test/test_lib/test_component_builder_spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ class MyIfComp {
4545
showMore: boolean = false;
4646
}
4747

48+
@Component({selector: 'child-child-comp'})
49+
@View({template: `<span>ChildChild</span>`})
50+
@Injectable()
51+
class ChildChildComp {}
52+
53+
@Component({selector: 'child-comp'})
54+
@View({template: `<span>Original {{childBinding}}(<child-child-comp></child-child-comp>)</span>`,
55+
directives: [ChildChildComp]})
56+
@Injectable()
57+
class ChildWithChildComp {
58+
childBinding: string;
59+
constructor() { this.childBinding = 'Child'; }
60+
}
61+
62+
@Component({selector: 'child-child-comp'})
63+
@View({template: `<span>ChildChild Mock</span>`})
64+
@Injectable()
65+
class MockChildChildComp {}
66+
67+
4868
export function main() {
4969
describe('test component builder', function() {
5070
it('should instantiate a component with valid DOM',
@@ -112,5 +132,20 @@ export function main() {
112132
async.done();
113133
});
114134
}));
135+
136+
137+
it("should override child component's dependencies",
138+
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
139+
140+
tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp)
141+
.overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp)
142+
.createAsync(ParentComp)
143+
.then((rootTestComponent) => {
144+
rootTestComponent.detectChanges();
145+
expect(rootTestComponent.nativeElement).toHaveText('Parent(Original Child(ChildChild Mock))');
146+
147+
async.done();
148+
});
149+
}));
115150
});
116151
}

0 commit comments

Comments
 (0)