2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 12:47:54 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2017-08-16 12:00:03 -04:00
|
|
|
import {core} from '@angular/compiler';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {DirectiveResolver} from '@angular/compiler/src/directive_resolver';
|
2016-09-12 22:14:17 -04:00
|
|
|
import {Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Input, Output, ViewChild, ViewChildren} from '@angular/core/src/metadata';
|
2017-08-16 12:00:03 -04:00
|
|
|
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
2015-09-03 18:10:48 -04:00
|
|
|
|
|
|
|
@Directive({selector: 'someDirective'})
|
|
|
|
class SomeDirective {
|
|
|
|
}
|
|
|
|
|
2015-09-30 23:59:23 -04:00
|
|
|
@Directive({selector: 'someDirective', inputs: ['c']})
|
2015-10-02 19:21:49 -04:00
|
|
|
class SomeDirectiveWithInputs {
|
2016-07-11 18:27:57 -04:00
|
|
|
@Input() a: any;
|
|
|
|
@Input('renamed') b: any;
|
|
|
|
c: any;
|
2015-09-03 18:10:48 -04:00
|
|
|
}
|
|
|
|
|
2015-09-30 23:59:23 -04:00
|
|
|
@Directive({selector: 'someDirective', outputs: ['c']})
|
|
|
|
class SomeDirectiveWithOutputs {
|
2016-07-11 18:27:57 -04:00
|
|
|
@Output() a: any;
|
|
|
|
@Output('renamed') b: any;
|
|
|
|
c: any;
|
2015-09-03 18:10:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Directive({selector: 'someDirective'})
|
|
|
|
class SomeDirectiveWithSetterProps {
|
2016-06-08 19:38:52 -04:00
|
|
|
@Input('renamed')
|
2020-04-08 13:14:18 -04:00
|
|
|
set a(value: any) {
|
|
|
|
}
|
2015-09-03 18:10:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Directive({selector: 'someDirective'})
|
2015-09-30 23:59:23 -04:00
|
|
|
class SomeDirectiveWithGetterOutputs {
|
2016-06-08 19:38:52 -04:00
|
|
|
@Output('renamed')
|
2020-04-08 13:14:18 -04:00
|
|
|
get a(): any {
|
|
|
|
return null;
|
|
|
|
}
|
2015-09-03 18:10:48 -04:00
|
|
|
}
|
|
|
|
|
2015-09-04 17:07:16 -04:00
|
|
|
@Directive({selector: 'someDirective', host: {'[c]': 'c'}})
|
|
|
|
class SomeDirectiveWithHostBindings {
|
2016-07-11 18:27:57 -04:00
|
|
|
@HostBinding() a: any;
|
|
|
|
@HostBinding('renamed') b: any;
|
|
|
|
c: any;
|
2015-09-04 17:07:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Directive({selector: 'someDirective', host: {'(c)': 'onC()'}})
|
|
|
|
class SomeDirectiveWithHostListeners {
|
|
|
|
@HostListener('a')
|
2020-04-08 13:14:18 -04:00
|
|
|
onA() {
|
|
|
|
}
|
2015-09-04 17:07:16 -04:00
|
|
|
@HostListener('b', ['$event.value'])
|
2020-04-08 13:14:18 -04:00
|
|
|
onB(value: any) {
|
|
|
|
}
|
2015-09-04 17:07:16 -04:00
|
|
|
}
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
@Directive({selector: 'someDirective', queries: {'cs': new ContentChildren('c')}})
|
2015-09-17 21:45:49 -04:00
|
|
|
class SomeDirectiveWithContentChildren {
|
2016-06-08 19:38:52 -04:00
|
|
|
@ContentChildren('a') as: any;
|
2016-07-11 18:27:57 -04:00
|
|
|
c: any;
|
2015-09-17 21:45:49 -04:00
|
|
|
}
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
@Directive({selector: 'someDirective', queries: {'cs': new ViewChildren('c')}})
|
2015-09-17 21:45:49 -04:00
|
|
|
class SomeDirectiveWithViewChildren {
|
2016-06-08 19:38:52 -04:00
|
|
|
@ViewChildren('a') as: any;
|
2016-07-11 18:27:57 -04:00
|
|
|
c: any;
|
2015-09-17 21:45:49 -04:00
|
|
|
}
|
2015-09-03 18:10:48 -04:00
|
|
|
|
2019-10-05 04:04:54 -04:00
|
|
|
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c')}})
|
2015-09-19 21:39:35 -04:00
|
|
|
class SomeDirectiveWithContentChild {
|
2019-10-05 04:04:54 -04:00
|
|
|
@ContentChild('a') a: any;
|
2016-07-11 18:27:57 -04:00
|
|
|
c: any;
|
2015-09-19 21:39:35 -04:00
|
|
|
}
|
|
|
|
|
2019-10-05 04:04:54 -04:00
|
|
|
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c')}})
|
2015-09-19 21:39:35 -04:00
|
|
|
class SomeDirectiveWithViewChild {
|
2019-10-05 04:04:54 -04:00
|
|
|
@ViewChild('a') a: any;
|
2016-07-11 18:27:57 -04:00
|
|
|
c: any;
|
2015-09-19 21:39:35 -04:00
|
|
|
}
|
|
|
|
|
2017-07-28 09:58:28 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'sample',
|
|
|
|
template: 'some template',
|
|
|
|
styles: ['some styles'],
|
|
|
|
preserveWhitespaces: true
|
|
|
|
})
|
2016-07-28 09:31:26 -04:00
|
|
|
class ComponentWithTemplate {
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:07:01 -04:00
|
|
|
@Directive({
|
|
|
|
selector: 'someDirective',
|
|
|
|
host: {'[decorator]': 'decorator'},
|
|
|
|
inputs: ['decorator'],
|
|
|
|
})
|
|
|
|
class SomeDirectiveWithSameHostBindingAndInput {
|
|
|
|
@Input() @HostBinding() prop: any;
|
|
|
|
}
|
|
|
|
|
2016-10-07 16:53:53 -04:00
|
|
|
@Directive({selector: 'someDirective'})
|
|
|
|
class SomeDirectiveWithMalformedHostBinding1 {
|
|
|
|
@HostBinding('(a)')
|
2020-04-08 13:14:18 -04:00
|
|
|
onA() {
|
|
|
|
}
|
2016-10-07 16:53:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Directive({selector: 'someDirective'})
|
|
|
|
class SomeDirectiveWithMalformedHostBinding2 {
|
|
|
|
@HostBinding('[a]')
|
2020-04-08 13:14:18 -04:00
|
|
|
onA() {
|
|
|
|
}
|
2016-10-07 16:53:53 -04:00
|
|
|
}
|
|
|
|
|
2015-09-03 18:10:48 -04:00
|
|
|
class SomeDirectiveWithoutMetadata {}
|
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('DirectiveResolver', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
let resolver: DirectiveResolver;
|
2015-09-03 18:10:48 -04:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
resolver = new DirectiveResolver(new JitReflector());
|
|
|
|
});
|
2015-09-03 18:10:48 -04:00
|
|
|
|
|
|
|
it('should read out the Directive metadata', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirective);
|
2017-08-16 12:00:03 -04:00
|
|
|
expect(directiveMetadata).toEqual(core.createDirective({
|
2017-05-23 13:52:40 -04:00
|
|
|
selector: 'someDirective',
|
|
|
|
inputs: [],
|
|
|
|
outputs: [],
|
|
|
|
host: {},
|
|
|
|
queries: {},
|
2017-11-29 19:29:05 -05:00
|
|
|
guards: {},
|
2017-05-23 13:52:40 -04:00
|
|
|
exportAs: undefined,
|
|
|
|
providers: undefined
|
|
|
|
}));
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw if not matching metadata is found', () => {
|
2016-06-08 19:38:52 -04:00
|
|
|
expect(() => {
|
|
|
|
resolver.resolve(SomeDirectiveWithoutMetadata);
|
|
|
|
}).toThrowError('No Directive annotation found on SomeDirectiveWithoutMetadata');
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
|
2016-11-18 18:17:44 -05:00
|
|
|
it('should support inheriting the Directive metadata', function() {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChildNoDecorator extends Parent {}
|
|
|
|
|
|
|
|
@Directive({selector: 'c'})
|
|
|
|
class ChildWithDecorator extends Parent {
|
|
|
|
}
|
|
|
|
|
2017-08-16 12:00:03 -04:00
|
|
|
expect(resolver.resolve(ChildNoDecorator)).toEqual(core.createDirective({
|
2017-05-23 13:52:40 -04:00
|
|
|
selector: 'p',
|
|
|
|
inputs: [],
|
|
|
|
outputs: [],
|
|
|
|
host: {},
|
|
|
|
queries: {},
|
2017-11-29 19:29:05 -05:00
|
|
|
guards: {},
|
2017-05-23 13:52:40 -04:00
|
|
|
exportAs: undefined,
|
|
|
|
providers: undefined
|
|
|
|
}));
|
|
|
|
|
2017-08-16 12:00:03 -04:00
|
|
|
expect(resolver.resolve(ChildWithDecorator)).toEqual(core.createDirective({
|
2017-05-23 13:52:40 -04:00
|
|
|
selector: 'c',
|
|
|
|
inputs: [],
|
|
|
|
outputs: [],
|
|
|
|
host: {},
|
|
|
|
queries: {},
|
2017-11-29 19:29:05 -05:00
|
|
|
guards: {},
|
2017-05-23 13:52:40 -04:00
|
|
|
exportAs: undefined,
|
|
|
|
providers: undefined
|
|
|
|
}));
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
|
2015-09-30 23:59:23 -04:00
|
|
|
describe('inputs', () => {
|
|
|
|
it('should append directive inputs', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithInputs);
|
2015-09-30 23:59:23 -04:00
|
|
|
expect(directiveMetadata.inputs).toEqual(['c', 'a', 'b: renamed']);
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with getters and setters', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithSetterProps);
|
2015-09-30 23:59:23 -04:00
|
|
|
expect(directiveMetadata.inputs).toEqual(['a: renamed']);
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
2015-10-02 19:21:49 -04:00
|
|
|
|
2016-11-18 18:17:44 -05:00
|
|
|
it('should remove duplicate inputs', () => {
|
|
|
|
@Directive({selector: 'someDirective', inputs: ['a', 'a']})
|
|
|
|
class SomeDirectiveWithDuplicateInputs {
|
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithDuplicateInputs);
|
|
|
|
expect(directiveMetadata.inputs).toEqual(['a']);
|
2016-07-11 19:01:49 -04:00
|
|
|
});
|
|
|
|
|
2016-11-18 18:17:44 -05:00
|
|
|
it('should use the last input if duplicate inputs (with rename)', () => {
|
|
|
|
@Directive({selector: 'someDirective', inputs: ['a', 'localA: a']})
|
|
|
|
class SomeDirectiveWithDuplicateInputs {
|
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithDuplicateInputs);
|
|
|
|
expect(directiveMetadata.inputs).toEqual(['localA: a']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prefer @Input over @Directive.inputs', () => {
|
|
|
|
@Directive({selector: 'someDirective', inputs: ['a']})
|
|
|
|
class SomeDirectiveWithDuplicateInputs {
|
2020-04-08 13:14:18 -04:00
|
|
|
@Input('a') propA: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithDuplicateInputs);
|
|
|
|
expect(directiveMetadata.inputs).toEqual(['propA: a']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support inheriting inputs', () => {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@Input() p1: any;
|
|
|
|
@Input('p21') p2: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class Child extends Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@Input('p22') p2: any;
|
|
|
|
@Input() p3: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(Child);
|
|
|
|
expect(directiveMetadata.inputs).toEqual(['p1', 'p2: p22', 'p3']);
|
2016-07-11 19:01:49 -04:00
|
|
|
});
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
|
2015-09-30 23:59:23 -04:00
|
|
|
describe('outputs', () => {
|
|
|
|
it('should append directive outputs', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithOutputs);
|
2015-09-30 23:59:23 -04:00
|
|
|
expect(directiveMetadata.outputs).toEqual(['c', 'a', 'b: renamed']);
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with getters and setters', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithGetterOutputs);
|
2015-09-30 23:59:23 -04:00
|
|
|
expect(directiveMetadata.outputs).toEqual(['a: renamed']);
|
2015-09-04 17:07:16 -04:00
|
|
|
});
|
2015-11-04 04:08:51 -05:00
|
|
|
|
2016-11-18 18:17:44 -05:00
|
|
|
it('should remove duplicate outputs', () => {
|
|
|
|
@Directive({selector: 'someDirective', outputs: ['a', 'a']})
|
|
|
|
class SomeDirectiveWithDuplicateOutputs {
|
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithDuplicateOutputs);
|
|
|
|
expect(directiveMetadata.outputs).toEqual(['a']);
|
2015-11-04 04:08:51 -05:00
|
|
|
});
|
2016-07-11 19:01:49 -04:00
|
|
|
|
2016-11-18 18:17:44 -05:00
|
|
|
it('should use the last output if duplicate outputs (with rename)', () => {
|
|
|
|
@Directive({selector: 'someDirective', outputs: ['a', 'localA: a']})
|
|
|
|
class SomeDirectiveWithDuplicateOutputs {
|
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithDuplicateOutputs);
|
|
|
|
expect(directiveMetadata.outputs).toEqual(['localA: a']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prefer @Output over @Directive.outputs', () => {
|
|
|
|
@Directive({selector: 'someDirective', outputs: ['a']})
|
|
|
|
class SomeDirectiveWithDuplicateOutputs {
|
2020-04-08 13:14:18 -04:00
|
|
|
@Output('a') propA: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithDuplicateOutputs);
|
|
|
|
expect(directiveMetadata.outputs).toEqual(['propA: a']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support inheriting outputs', () => {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@Output() p1: any;
|
|
|
|
@Output('p21') p2: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class Child extends Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@Output('p22') p2: any;
|
|
|
|
@Output() p3: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(Child);
|
|
|
|
expect(directiveMetadata.outputs).toEqual(['p1', 'p2: p22', 'p3']);
|
2016-07-11 19:01:49 -04:00
|
|
|
});
|
2015-09-04 17:07:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('host', () => {
|
|
|
|
it('should append host bindings', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithHostBindings);
|
2015-09-04 17:07:16 -04:00
|
|
|
expect(directiveMetadata.host).toEqual({'[c]': 'c', '[a]': 'a', '[renamed]': 'b'});
|
|
|
|
});
|
|
|
|
|
2016-09-27 19:07:01 -04:00
|
|
|
it('should append host binding and input on the same property', () => {
|
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithSameHostBindingAndInput);
|
|
|
|
expect(directiveMetadata.host).toEqual({'[decorator]': 'decorator', '[prop]': 'prop'});
|
|
|
|
expect(directiveMetadata.inputs).toEqual(['decorator', 'prop']);
|
|
|
|
});
|
|
|
|
|
2015-09-04 17:07:16 -04:00
|
|
|
it('should append host listeners', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithHostListeners);
|
2015-09-04 17:07:16 -04:00
|
|
|
expect(directiveMetadata.host)
|
|
|
|
.toEqual({'(c)': 'onC()', '(a)': 'onA()', '(b)': 'onB($event.value)'});
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
2016-10-07 16:53:53 -04:00
|
|
|
|
|
|
|
it('should throw when @HostBinding name starts with "("', () => {
|
|
|
|
expect(() => resolver.resolve(SomeDirectiveWithMalformedHostBinding1))
|
|
|
|
.toThrowError('@HostBinding can not bind to events. Use @HostListener instead.');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw when @HostBinding name starts with "["', () => {
|
|
|
|
expect(() => resolver.resolve(SomeDirectiveWithMalformedHostBinding2))
|
|
|
|
.toThrowError(
|
|
|
|
`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
|
|
|
|
});
|
2016-11-18 18:17:44 -05:00
|
|
|
|
|
|
|
it('should support inheriting host bindings', () => {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@HostBinding() p1: any;
|
|
|
|
@HostBinding('p21') p2: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class Child extends Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@HostBinding('p22') p2: any;
|
|
|
|
@HostBinding() p3: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(Child);
|
2016-12-14 17:31:57 -05:00
|
|
|
expect(directiveMetadata.host)
|
|
|
|
.toEqual({'[p1]': 'p1', '[p21]': 'p2', '[p22]': 'p2', '[p3]': 'p3'});
|
2016-11-18 18:17:44 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should support inheriting host listeners', () => {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
|
|
|
@HostListener('p1')
|
2020-04-08 13:14:18 -04:00
|
|
|
p1() {
|
|
|
|
}
|
2016-11-18 18:17:44 -05:00
|
|
|
@HostListener('p21')
|
2020-04-08 13:14:18 -04:00
|
|
|
p2() {
|
|
|
|
}
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class Child extends Parent {
|
|
|
|
@HostListener('p22')
|
2020-04-08 13:14:18 -04:00
|
|
|
p2() {
|
|
|
|
}
|
2016-11-18 18:17:44 -05:00
|
|
|
@HostListener('p3')
|
2020-04-08 13:14:18 -04:00
|
|
|
p3() {
|
|
|
|
}
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(Child);
|
2016-12-14 17:31:57 -05:00
|
|
|
expect(directiveMetadata.host)
|
|
|
|
.toEqual({'(p1)': 'p1()', '(p21)': 'p2()', '(p22)': 'p2()', '(p3)': 'p3()'});
|
2016-11-18 18:17:44 -05:00
|
|
|
});
|
2016-12-14 17:31:57 -05:00
|
|
|
|
|
|
|
it('should combine host bindings and listeners during inheritance', () => {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@HostListener('p11')
|
|
|
|
@HostListener('p12')
|
|
|
|
p1() {
|
|
|
|
}
|
2016-12-14 17:31:57 -05:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
@HostBinding('p21') @HostBinding('p22') p2: any;
|
2016-12-14 17:31:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class Child extends Parent {
|
|
|
|
@HostListener('c1')
|
2020-04-08 13:14:18 -04:00
|
|
|
p1() {
|
|
|
|
}
|
2016-12-14 17:31:57 -05:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
@HostBinding('c2') p2: any;
|
2016-12-14 17:31:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(Child);
|
|
|
|
expect(directiveMetadata.host).toEqual({
|
|
|
|
'(p11)': 'p1()',
|
|
|
|
'(p12)': 'p1()',
|
|
|
|
'(c1)': 'p1()',
|
|
|
|
'[p21]': 'p2',
|
|
|
|
'[p22]': 'p2',
|
|
|
|
'[c2]': 'p2'
|
|
|
|
});
|
2016-12-14 18:10:43 -05:00
|
|
|
});
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
2015-09-17 21:45:49 -04:00
|
|
|
|
|
|
|
describe('queries', () => {
|
|
|
|
it('should append ContentChildren', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithContentChildren);
|
2015-09-17 21:45:49 -04:00
|
|
|
expect(directiveMetadata.queries)
|
2016-06-08 19:38:52 -04:00
|
|
|
.toEqual({'cs': new ContentChildren('c'), 'as': new ContentChildren('a')});
|
2015-09-17 21:45:49 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should append ViewChildren', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithViewChildren);
|
2015-09-17 21:45:49 -04:00
|
|
|
expect(directiveMetadata.queries)
|
2016-06-08 19:38:52 -04:00
|
|
|
.toEqual({'cs': new ViewChildren('c'), 'as': new ViewChildren('a')});
|
2015-09-17 21:45:49 -04:00
|
|
|
});
|
2015-09-19 21:39:35 -04:00
|
|
|
|
|
|
|
it('should append ContentChild', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithContentChild);
|
2019-10-05 04:04:54 -04:00
|
|
|
expect(directiveMetadata.queries)
|
|
|
|
.toEqual({'c': new ContentChild('c'), 'a': new ContentChild('a')});
|
2015-09-19 21:39:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should append ViewChild', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithViewChild);
|
2019-10-05 04:04:54 -04:00
|
|
|
expect(directiveMetadata.queries)
|
|
|
|
.toEqual({'c': new ViewChild('c'), 'a': new ViewChild('a')});
|
2015-09-19 21:39:35 -04:00
|
|
|
});
|
2016-11-18 18:17:44 -05:00
|
|
|
|
|
|
|
it('should support inheriting queries', () => {
|
|
|
|
@Directive({selector: 'p'})
|
|
|
|
class Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@ContentChild('p1') p1: any;
|
|
|
|
@ContentChild('p21') p2: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class Child extends Parent {
|
2020-04-08 13:14:18 -04:00
|
|
|
@ContentChild('p22') p2: any;
|
|
|
|
@ContentChild('p3') p3: any;
|
2016-11-18 18:17:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const directiveMetadata = resolver.resolve(Child);
|
|
|
|
expect(directiveMetadata.queries).toEqual({
|
2019-10-05 04:04:54 -04:00
|
|
|
'p1': new ContentChild('p1'),
|
|
|
|
'p2': new ContentChild('p22'),
|
|
|
|
'p3': new ContentChild('p3')
|
2016-11-18 18:17:44 -05:00
|
|
|
});
|
|
|
|
});
|
2015-09-17 21:45:49 -04:00
|
|
|
});
|
2016-07-28 09:31:26 -04:00
|
|
|
|
2016-09-27 18:41:37 -04:00
|
|
|
describe('Component', () => {
|
2016-07-28 09:31:26 -04:00
|
|
|
it('should read out the template related metadata from the Component metadata', () => {
|
2016-09-27 18:41:37 -04:00
|
|
|
const compMetadata: Component = resolver.resolve(ComponentWithTemplate);
|
2016-07-28 09:31:26 -04:00
|
|
|
expect(compMetadata.template).toEqual('some template');
|
|
|
|
expect(compMetadata.styles).toEqual(['some styles']);
|
2017-07-28 09:58:28 -04:00
|
|
|
expect(compMetadata.preserveWhitespaces).toBe(true);
|
2016-07-28 09:31:26 -04:00
|
|
|
});
|
|
|
|
});
|
2015-09-03 18:10:48 -04:00
|
|
|
});
|
|
|
|
}
|