feat: alllow specifying directives as bindings
Related to #709 Closes #1498
This commit is contained in:
committed by
Tobias Bosch
parent
6896305e34
commit
4bab25b366
@@ -274,6 +274,31 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should allow specifying directives as bindings', inject([TestBed, AsyncTestCompleter], (tb, async) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
template: '<child-cmp></child-cmp>',
|
||||
directives: [bind(ChildComp).toClass(ChildComp)]
|
||||
}));
|
||||
|
||||
tb.createView(MyComp, {context: ctx}).then((view) => {
|
||||
view.detectChanges();
|
||||
|
||||
expect(view.rootNodes).toHaveText('hello');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should read directives metadata from their binding token', inject([TestBed, AsyncTestCompleter], (tb, async) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
template: '<div public-api><div needs-public-api></div></div>',
|
||||
directives: [bind(PublicApi).toClass(PrivateImpl), NeedsPublicApi]
|
||||
}));
|
||||
|
||||
tb.createView(MyComp, {context: ctx}).then((view) => {
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support template directives via `<template>` elements.', inject([TestBed, AsyncTestCompleter], (tb, async) => {
|
||||
tb.overrideView(MyComp,
|
||||
new View({
|
||||
@@ -1191,3 +1216,24 @@ class NeedsAttribute {
|
||||
this.fooAttribute = fooAttribute;
|
||||
}
|
||||
}
|
||||
|
||||
@Decorator({
|
||||
selector: '[public-api]'
|
||||
})
|
||||
class PublicApi {
|
||||
}
|
||||
|
||||
@Decorator({
|
||||
selector: '[private-impl]'
|
||||
})
|
||||
class PrivateImpl extends PublicApi {
|
||||
}
|
||||
|
||||
@Decorator({
|
||||
selector: '[needs-public-api]'
|
||||
})
|
||||
class NeedsPublicApi {
|
||||
constructor(@Parent() api:PublicApi) {
|
||||
expect(api instanceof PrivateImpl).toBe(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user