test: fix existing tests by removing usage of obsolete stuff like component level directives, AsyncCompleter and TestComponentBuilder

This commit is contained in:
Igor Minar 2016-08-19 12:51:01 -07:00
parent 939d318242
commit 3c2b2ff332
46 changed files with 251 additions and 326 deletions

View File

@ -378,7 +378,7 @@ export function main() {
});
}
@Component({selector: 'test-cmp', directives: [NgClass, NgFor], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
condition: boolean = true;
items: any[];

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgFor, NgIf} from '@angular/common';
import {CommonModule} from '@angular/common';
import {Component, ContentChild, TemplateRef} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {expect} from '@angular/platform-browser/testing/matchers';
@ -23,9 +22,8 @@ export function main() {
'<div><copy-me template="ngFor let item of items">{{item.toString()}};</copy-me></div>';
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent, ComponentUsingTestComponent],
});
TestBed.configureTestingModule(
{declarations: [TestComponent, ComponentUsingTestComponent], imports: [CommonModule]});
});
it('should reflect initial elements', async(() => {
@ -420,7 +418,7 @@ class Foo {
toString() { return 'foo'; }
}
@Component({selector: 'test-cmp', directives: [NgFor, NgIf], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
@ContentChild(TemplateRef) contentTpl: TemplateRef<Object>;
items: any;
@ -430,7 +428,7 @@ class TestComponent {
trackByContext(): void { thisArg = this; }
}
@Component({selector: 'outer-cmp', directives: [TestComponent], template: ''})
@Component({selector: 'outer-cmp', template: ''})
class ComponentUsingTestComponent {
items: any;
constructor() { this.items = [1, 2]; }

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgIf} from '@angular/common';
import {CommonModule} from '@angular/common';
import {Component} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {expect} from '@angular/platform-browser/testing/matchers';
@ -17,9 +16,7 @@ export function main() {
describe('ngIf directive', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
});
TestBed.configureTestingModule({declarations: [TestComponent], imports: [CommonModule]});
});
it('should work in a template attribute', async(() => {
@ -171,7 +168,7 @@ export function main() {
});
}
@Component({selector: 'test-cmp', directives: [NgIf], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
booleanCondition: boolean;
nestedBooleanCondition: boolean;

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgLocalization, NgPlural, NgPluralCase} from '@angular/common';
import {CommonModule, NgLocalization} from '@angular/common';
import {Component, Injectable} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
export function main() {
@ -18,7 +17,8 @@ export function main() {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
providers: [{provide: NgLocalization, useClass: TestLocalization}]
providers: [{provide: NgLocalization, useClass: TestLocalization}],
imports: [CommonModule]
});
});
@ -139,7 +139,7 @@ class TestLocalization extends NgLocalization {
}
}
@Component({selector: 'test-cmp', directives: [NgPlural, NgPluralCase], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
switchValue: number = null;
}

View File

@ -6,12 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, it, xit,} from '@angular/core/testing/testing_internal';
import {async, TestBed, ComponentFixture} from '@angular/core/testing';
import {CommonModule} from '@angular/common';
import {Component} from '@angular/core';
import {NgStyle} from '@angular/common/src/directives/ng_style';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
function expectNativeEl(fixture: ComponentFixture<any>) {
return <any>expect(fixture.debugElement.children[0].nativeElement);
@ -21,9 +18,7 @@ export function main() {
describe('binding to CSS styles', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
});
TestBed.configureTestingModule({declarations: [TestComponent], imports: [CommonModule]});
});
it('should add styles specified in an object literal', async(() => {
@ -154,7 +149,7 @@ export function main() {
});
}
@Component({selector: 'test-cmp', directives: [NgStyle], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
expr: any;
}

View File

@ -6,19 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common';
import {CommonModule} from '@angular/common';
import {Component} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
export function main() {
describe('switch', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
});
TestBed.configureTestingModule({declarations: [TestComponent], imports: [CommonModule]});
});
describe('switch value changes', () => {
@ -149,8 +146,7 @@ export function main() {
});
}
@Component(
{selector: 'test-cmp', directives: [NgSwitch, NgSwitchCase, NgSwitchDefault], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
switchValue: any;
when1: any;

View File

@ -6,19 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgTemplateOutlet} from '@angular/common';
import {CommonModule} from '@angular/common';
import {Component, ContentChildren, Directive, QueryList, TemplateRef} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
export function main() {
describe('insert', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
});
TestBed.configureTestingModule(
{declarations: [TestComponent, CaptureTplRefs], imports: [CommonModule]});
});
it('should do nothing if templateRef is null', async(() => {
@ -160,7 +158,7 @@ class CaptureTplRefs {
@ContentChildren(TemplateRef) tplRefs: QueryList<TemplateRef<any>>;
}
@Component({selector: 'test-cmp', directives: [NgTemplateOutlet, CaptureTplRefs], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
currentTplRef: TemplateRef<any>;
context: any = {foo: 'bar'};

View File

@ -9,7 +9,6 @@
import {Component, Directive} from '@angular/core';
import {ElementRef} from '@angular/core/src/linker/element_ref';
import {TestBed, async} from '@angular/core/testing';
import {beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {expect} from '@angular/platform-browser/testing/matchers';
@ -18,7 +17,7 @@ export function main() {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
declarations: [TestComponent, TestDirective],
});
});
@ -58,7 +57,7 @@ class TestDirective {
constructor(el: ElementRef) { getDOM().addClass(el.nativeElement, 'compiled'); }
}
@Component({selector: 'test-cmp', directives: [TestDirective], template: ''})
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
text: string;
constructor() { this.text = 'foo'; }

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {JsonPipe} from '@angular/common';
import {CommonModule, JsonPipe} from '@angular/common';
import {Component} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
import {Json, StringWrapper} from '../../src/facade/lang';
@ -56,10 +55,13 @@ export function main() {
describe('integration', () => {
@Component({selector: 'test-comp', template: '{{data | json}}'})
class TestComp {
data: any;
}
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComp],
});
TestBed.configureTestingModule({declarations: [TestComp], imports: [CommonModule]});
});
it('should work with mutable objects', async(() => {
@ -77,8 +79,3 @@ export function main() {
});
});
}
@Component({selector: 'test-comp', template: '{{data | json}}', pipes: [JsonPipe]})
class TestComp {
data: any;
}

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {SlicePipe} from '@angular/common';
import {CommonModule, SlicePipe} from '@angular/common';
import {Component} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
import {expect} from '@angular/platform-browser/testing/matchers';
@ -88,10 +87,14 @@ export function main() {
});
describe('integration', () => {
@Component({selector: 'test-comp', template: '{{(data | slice:1).join(",") }}'})
class TestComp {
data: any;
}
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComp],
});
TestBed.configureTestingModule({declarations: [TestComp], imports: [CommonModule]});
});
it('should work with mutable arrays', async(() => {
@ -108,8 +111,3 @@ export function main() {
});
});
}
@Component({selector: 'test-comp', template: '{{(data | slice:1).join(",") }}', pipes: [SlicePipe]})
class TestComp {
data: any;
}

View File

@ -8,7 +8,7 @@
import {Component} from '@angular/core';
@Component({selector: 'my-comp', template: '<div></div>', directives: [NextComp]})
@Component({selector: 'my-comp', template: '<div></div>'})
export class MultipleComponentsMyComp {
}

View File

@ -17,7 +17,6 @@ import {MultipleComponentsMyComp} from './a/multiple_components';
templateUrl: './basic.html',
styles: ['.red { color: red }'],
styleUrls: ['./basic.css'],
directives: [MultipleComponentsMyComp, FORM_DIRECTIVES, NgIf, NgFor]
})
export class BasicComp {
ctxProp: string;

View File

@ -32,8 +32,7 @@ export class CompWithProviders {
template: `
<input #a>{{a.value}}
<div *ngIf="true">{{a.value}}</div>
`,
directives: [wrapInArray(common.NgIf)]
`
})
export class CompWithReferences {
}
@ -51,6 +50,6 @@ export class CompUsingPipes {
export class CompUsingCustomElements {
}
@NgModule({schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [CompUsingCustomElements]})
@NgModule({schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: wrapInArray(CompUsingCustomElements)})
export class ModuleUsingCustomElements {
}

View File

@ -11,20 +11,22 @@ import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {MdButtonModule} from '@angular2-material/button';
import {MultipleComponentsMyComp, NextComp} from './a/multiple_components';
import {AnimateCmp} from './animate';
import {BasicComp} from './basic';
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components';
import {CompUsingPipes, CompWithProviders, CompWithReferences, ModuleUsingCustomElements} from './features';
import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomePipeInRootModule, SomeService, someLibModuleWithProviders} from './module_fixtures';
import {ProjectingComp} from './projection';
import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
import {CompWithNgContent, ProjectingComp} from './projection';
import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, DirectiveForQuery} from './queries';
@NgModule({
declarations: [
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithEntryComponents,
CompWithAnalyzeEntryComponentsProvider, ProjectingComp, CompWithChildQuery,
CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
CompWithReferences, CompUsingPipes
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompForChildQuery,
CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider, ProjectingComp,
CompWithChildQuery, CompWithDirectiveChild, CompWithNgContent,
CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences, CompUsingPipes,
MultipleComponentsMyComp, DirectiveForQuery, NextComp
],
imports: [
BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements,

View File

@ -14,8 +14,7 @@ export class CompWithNgContent {
@Component({
selector: 'main',
template: '<comp-with-proj><span greeting="Hello world!"></span></comp-with-proj>',
directives: [CompWithNgContent]
template: '<comp-with-proj><span greeting="Hello world!"></span></comp-with-proj>'
})
export class ProjectingComp {
}

View File

@ -13,11 +13,8 @@ import {Component, Directive, QueryList, ViewChild, ViewChildren} from '@angular
export class CompForChildQuery {
}
@Component({
selector: 'comp-with-child-query',
template: '<comp-for-child-query></comp-for-child-query>',
directives: [CompForChildQuery]
})
@Component(
{selector: 'comp-with-child-query', template: '<comp-for-child-query></comp-for-child-query>'})
export class CompWithChildQuery {
@ViewChild(CompForChildQuery) child: CompForChildQuery;
@ViewChildren(CompForChildQuery) children: QueryList<CompForChildQuery>;
@ -29,7 +26,6 @@ export class DirectiveForQuery {
@Component({
selector: 'comp-with-directive-child',
directives: [DirectiveForQuery, NgFor],
template: `<div>
<div *ngFor="let data of divData" directive-for-query>{{data}}</div>
</div>`

View File

@ -166,7 +166,7 @@ export class CodeGenerator {
const resolver = new CompileMetadataResolver(
new compiler.NgModuleResolver(staticReflector),
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
config, console, elementSchemaRegistry, staticReflector);
elementSchemaRegistry, staticReflector);
// TODO(vicb): do not pass cliOptions.i18nFormat here
const offlineCompiler = new compiler.OfflineCompiler(
resolver, normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),

View File

@ -178,7 +178,7 @@ export class Extractor {
const resolver = new CompileMetadataResolver(
new compiler.NgModuleResolver(staticReflector),
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
config, console, elementSchemaRegistry, staticReflector);
elementSchemaRegistry, staticReflector);
const offlineCompiler = new compiler.OfflineCompiler(
resolver, normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost), null, null);

View File

@ -8,7 +8,6 @@
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector';
import {HostListenerMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal';
import {ListWrapper} from '@angular/facade/src/collection';
import {isBlank} from '@angular/facade/src/lang';
import {MetadataCollector} from '@angular/tsc-wrapped';
@ -65,8 +64,6 @@ describe('StaticReflector', () => {
expect(annotations.length).toEqual(1);
let annotation = annotations[0];
expect(annotation.selector).toEqual('my-hero-detail');
expect(annotation.directives).toEqual([[host.findDeclaration(
'angular2/src/common/directives/ng_for', 'NgFor')]]);
expect(annotation.animations).toEqual([trigger('myAnimation', [
state('state1', style({'background': 'white'})),
transition(
@ -596,13 +593,6 @@ class MockReflectorHost implements StaticReflectorHost {
'selector': 'my-hero-detail',
'template':
'\n <div *ngIf="hero">\n <h2>{{hero.name}} details!</h2>\n <div><label>id: </label>{{hero.id}}</div>\n <div>\n <label>name: </label>\n <input [(ngModel)]="hero.name" placeholder="name"/>\n </div>\n </div>\n',
'directives': [
{
'__symbolic': 'reference',
'name': 'FORM_DIRECTIVES',
'module': 'angular2/src/common/forms-deprecated/directives'
}
],
'animations': [{
'__symbolic': 'call',
'expression': {
@ -755,7 +745,7 @@ class MockReflectorHost implements StaticReflectorHost {
},
arguments: [
{
directives: [
entryComponents: [
{
__symbolic: 'reference',
module: 'src/error-references',
@ -957,14 +947,14 @@ class MockReflectorHost implements StaticReflectorHost {
@Component({
selector: 'my-component',
directives: [someFunction([NgIf])]
entryComponents: [someFunction([NgIf])]
})
export class MyComponent {}
@someFunction()
@Component({
selector: 'my-component',
directives: [NgIf]
entryComponents: [NgIf]
})
export class MyOtherComponent { }
`,

View File

@ -6,26 +6,20 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DirectiveResolver, ResourceLoader, i18n} from '@angular/compiler';
import {MockDirectiveResolver} from '@angular/compiler/testing';
import {Compiler, Component, DebugElement, Injector, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
import {TestBed, fakeAsync} from '@angular/core/testing';
import {beforeEach, TestComponentBuilder, ddescribe, describe, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {SpyResourceLoader} from '../spies';
import {NgLocalization} from '@angular/common';
import {ResourceLoader, i18n} from '@angular/compiler';
import {Component, DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {stringifyElement} from '@angular/platform-browser/testing/browser_util';
import {expect} from '@angular/platform-browser/testing/matchers';
import {SpyResourceLoader} from '../spies';
export function main() {
describe('i18n integration spec', () => {
let compiler: Compiler;
let xhr: SpyResourceLoader;
let tcb: TestComponentBuilder;
let dirResolver: MockDirectiveResolver;
let injector: Injector;
beforeEach(() => {
beforeEach(async(() => {
TestBed.configureCompiler({
providers: [
{provide: ResourceLoader, useClass: SpyResourceLoader},
@ -34,21 +28,15 @@ export function main() {
{provide: TRANSLATIONS_FORMAT, useValue: 'xtb'},
]
});
});
beforeEach(fakeAsync(inject(
[Compiler, TestComponentBuilder, ResourceLoader, DirectiveResolver, Injector],
(_compiler: Compiler, _tcb: TestComponentBuilder, _xhr: SpyResourceLoader,
_dirResolver: MockDirectiveResolver, _injector: Injector) => {
compiler = _compiler;
tcb = _tcb;
xhr = _xhr;
dirResolver = _dirResolver;
injector = _injector;
})));
TestBed.configureTestingModule({declarations: [I18nComponent]});
TestBed.compileComponents();
}));
it('translate templates', () => {
const tb = tcb.createSync(I18nComponent);
const tb = TestBed.createComponent(I18nComponent);
const cmp = tb.componentInstance;
const el = tb.debugElement;

View File

@ -6,14 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompilerConfig} from '@angular/compiler/src/config';
import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/testing/test_bindings';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, Component, Directive, DoCheck, Injectable, NgModule, OnChanges, OnDestroy, OnInit, Pipe, SimpleChanges, ViewEncapsulation} from '@angular/core';
import {LIFECYCLE_HOOKS_VALUES} from '@angular/core/src/metadata/lifecycle_hooks';
import {TestBed} from '@angular/core/testing';
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {TestBed, inject} from '@angular/core/testing';
import {CompileNgModuleMetadata} from '../src/compile_metadata';
import {stringify} from '../src/facade/lang';
import {CompileMetadataResolver} from '../src/metadata_resolver';
@ -190,7 +187,6 @@ class ComponentWithoutModuleId {
encapsulation: ViewEncapsulation.Emulated,
styles: ['someStyle'],
styleUrls: ['someStyleUrl'],
directives: [SomeDirective],
interpolation: ['{{', '}}']
})
class ComponentWithEverything implements OnChanges,

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgIf} from '@angular/common';
import {CommonModule} from '@angular/common';
import {AnimationDriver} from '@angular/platform-browser/src/dom/animation_driver';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {MockAnimationDriver} from '@angular/platform-browser/testing/mock_animation_driver';
@ -15,11 +15,10 @@ import {DEFAULT_STATE} from '../../src/animation/animation_constants';
import {AnimationKeyframe} from '../../src/animation/animation_keyframe';
import {AnimationPlayer} from '../../src/animation/animation_player';
import {AnimationStyles} from '../../src/animation/animation_styles';
import {AUTO_STYLE, AnimationEntryMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '../../src/animation/metadata';
import {AUTO_STYLE, animate, group, keyframes, sequence, state, style, transition, trigger} from '../../src/animation/metadata';
import {isPresent} from '../../src/facade/lang';
import {TestBed, fakeAsync, flushMicrotasks} from '../../testing';
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
import {beforeEach, ddescribe, describe, expect, iit, it, xdescribe, xit} from '../../testing/testing_internal';
export function main() {
describe('jit', () => { declareTests({useJit: true}); });
@ -32,7 +31,8 @@ function declareTests({useJit}: {useJit: boolean}) {
TestBed.configureCompiler({useJit: useJit});
TestBed.configureTestingModule({
declarations: [DummyLoadingCmp, DummyIfCmp],
providers: [{provide: AnimationDriver, useClass: MockAnimationDriver}]
providers: [{provide: AnimationDriver, useClass: MockAnimationDriver}],
imports: [CommonModule]
});
});
@ -1639,7 +1639,6 @@ class InnerContentTrackingAnimationPlayer extends MockAnimationPlayer {
@Component({
selector: 'if-cmp',
directives: [NgIf],
animations: [trigger('myAnimation', [])],
template: `
<div *ngIf="exp" [@myAnimation]="exp"></div>

View File

@ -8,14 +8,12 @@
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnInit} from '@angular/core';
import {Component, Directive} from '@angular/core/src/metadata';
import {ViewMetadata} from '@angular/core/src/metadata/view';
import {TestBed} from '@angular/core/testing';
import {AsyncTestCompleter, Log, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {TestBed, inject} from '@angular/core/testing';
import {Log} from '@angular/core/testing/testing_internal';
export function main() {
describe('directive lifecycle integration spec', () => {
let log: Log;
beforeEachProviders(() => { return [Log]; });
beforeEach(() => {
TestBed
@ -24,7 +22,8 @@ export function main() {
LifecycleCmp,
LifecycleDir,
MyComp5,
]
],
providers: [Log]
})
.overrideComponent(MyComp5, {set: {template: '<div [field]="123" lifecycle></div>'}});
});

View File

@ -6,15 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AsyncPipe, NgFor} from '@angular/common';
import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry';
import {MockSchemaRegistry} from '@angular/compiler/testing';
import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/testing/test_bindings';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentMetadata, DebugElement, Directive, DoCheck, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, RenderComponentType, Renderer, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewContainerRef, WrappedValue, forwardRef} from '@angular/core';
import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer';
import {ViewMetadata} from '@angular/core/src/metadata/view';
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {TestComponentBuilder, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DomRootRenderer} from '@angular/platform-browser/src/dom/dom_renderer';

View File

@ -9,7 +9,7 @@
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {Console} from '../../src/console';
import {stringify} from '../../src/facade/lang';
export function main() {
describe('jit', () => { declareTests({useJit: true}); });
@ -44,7 +44,8 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should resolve ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => {
TestBed.resetTestingModule();
TestBed.configureTestingModule({declarations: [CompWithAnalyzeEntryComponentsProvider]});
TestBed.configureTestingModule(
{declarations: [CompWithAnalyzeEntryComponentsProvider, NestedChildComp, ChildComp]});
let compFixture = TestBed.createComponent(CompWithAnalyzeEntryComponentsProvider);
let mainComp: CompWithAnalyzeEntryComponentsProvider = compFixture.componentInstance;
let cfr: ComponentFactoryResolver =

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AsyncPipe, NgFor, NgIf} from '@angular/common';
import {Compiler, Host, Inject, Injectable, Injector, NgModule, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf, SkipSelfMetadata, forwardRef} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ComponentFactory, Host, Inject, Injectable, Injector, NgModule, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf, SkipSelfMetadata, forwardRef} from '@angular/core';
import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection';
import {ComponentFactoryResolver} from '@angular/core/src/linker/component_factory_resolver';
import {ElementRef} from '@angular/core/src/linker/element_ref';
@ -16,10 +16,8 @@ import {TemplateRef, TemplateRef_} from '@angular/core/src/linker/template_ref';
import {ViewContainerRef} from '@angular/core/src/linker/view_container_ref';
import {EmbeddedViewRef} from '@angular/core/src/linker/view_ref';
import {Attribute, Component, ContentChildren, Directive, HostBinding, HostListener, Input, Output, Pipe} from '@angular/core/src/metadata';
import {ViewMetadata} from '@angular/core/src/metadata/view';
import {Renderer} from '@angular/core/src/render';
import {ComponentFixture, TestBed, async, fakeAsync, getTestBed, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {TestBed, async, fakeAsync, getTestBed, inject, tick} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {dispatchEvent, el} from '@angular/platform-browser/testing/browser_util';
import {expect} from '@angular/platform-browser/testing/matchers';
@ -381,8 +379,12 @@ function declareTests({useJit}: {useJit: boolean}) {
});
it('should allow to transplant TemplateRefs into other ViewContainers', () => {
TestBed.configureTestingModule(
{declarations: [MyComp, SomeDirective, CompWithHost, ToolbarComponent, ToolbarPart]});
TestBed.configureTestingModule({
declarations: [
MyComp, SomeDirective, CompWithHost, ToolbarComponent, ToolbarViewContainer, ToolbarPart
],
imports: [CommonModule]
});
const template =
'<some-directive><toolbar><template toolbarpart let-toolbarProp="toolbarProp">{{ctxProp}},{{toolbarProp}},<cmp-with-host></cmp-with-host></template></toolbar></some-directive>';
TestBed.overrideComponent(MyComp, {set: {template}});
@ -523,7 +525,8 @@ function declareTests({useJit}: {useJit: boolean}) {
});
it('should be checked when its bindings got updated', () => {
TestBed.configureTestingModule({declarations: [MyComp, [[PushCmp]]]});
TestBed.configureTestingModule(
{declarations: [MyComp, PushCmp, EventCmp], imports: [CommonModule]});
const template = '<push-cmp [prop]="ctxProp" #cmp></push-cmp>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
@ -559,7 +562,8 @@ function declareTests({useJit}: {useJit: boolean}) {
}
it('should be checked when an event is fired', () => {
TestBed.configureTestingModule({declarations: [MyComp, [[PushCmp]]]});
TestBed.configureTestingModule(
{declarations: [MyComp, PushCmp, EventCmp], imports: [CommonModule]});
const template = '<push-cmp [prop]="ctxProp" #cmp></push-cmp>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
@ -611,7 +615,8 @@ function declareTests({useJit}: {useJit: boolean}) {
if (getDOM().supportsDOMEvents()) {
it('should be checked when an async pipe requests a check', fakeAsync(() => {
TestBed.configureTestingModule({declarations: [MyComp, [[PushCmpWithAsyncPipe]]]});
TestBed.configureTestingModule(
{declarations: [MyComp, PushCmpWithAsyncPipe], imports: [CommonModule]});
const template = '<push-cmp-with-async #cmp></push-cmp-with-async>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
@ -670,92 +675,81 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
});
it('should support events via EventEmitter on regular elements', () => {
TestBed.configureTestingModule(
{declarations: [MyComp, DirectiveEmittingEvent, DirectiveListeningEvent]});
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const template = '<div emitter listener></div>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
it('should support events via EventEmitter on regular elements', async(() => {
TestBed.configureTestingModule(
{declarations: [MyComp, DirectiveEmittingEvent, DirectiveListeningEvent]});
const template = '<div emitter listener></div>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
var tc = fixture.debugElement.children[0];
var emitter = tc.injector.get(DirectiveEmittingEvent);
var listener = tc.injector.get(DirectiveListeningEvent);
var tc = fixture.debugElement.children[0];
var emitter = tc.injector.get(DirectiveEmittingEvent);
var listener = tc.injector.get(DirectiveListeningEvent);
expect(listener.msg).toEqual('');
var eventCount = 0;
expect(listener.msg).toEqual('');
var eventCount = 0;
emitter.event.subscribe({
next: () => {
eventCount++;
if (eventCount === 1) {
expect(listener.msg).toEqual('fired !');
fixture.destroy();
emitter.fireEvent('fired again !');
} else {
expect(listener.msg).toEqual('fired !');
async.done();
}
}
});
emitter.event.subscribe({
next: () => {
eventCount++;
if (eventCount === 1) {
expect(listener.msg).toEqual('fired !');
fixture.destroy();
emitter.fireEvent('fired again !');
} else {
expect(listener.msg).toEqual('fired !');
}
}
});
emitter.fireEvent('fired !');
});
});
emitter.fireEvent('fired !');
}));
it('should support events via EventEmitter on template elements', () => {
TestBed.configureTestingModule(
{declarations: [MyComp, DirectiveEmittingEvent, DirectiveListeningEvent]});
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const template = '<template emitter listener (event)="ctxProp=$event"></template>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
it('should support events via EventEmitter on template elements', async(() => {
TestBed.configureTestingModule(
{declarations: [MyComp, DirectiveEmittingEvent, DirectiveListeningEvent]});
const template = '<template emitter listener (event)="ctxProp=$event"></template>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
var tc = fixture.debugElement.childNodes[0];
var tc = fixture.debugElement.childNodes[0];
var emitter = tc.injector.get(DirectiveEmittingEvent);
var myComp = fixture.debugElement.injector.get(MyComp);
var listener = tc.injector.get(DirectiveListeningEvent);
var emitter = tc.injector.get(DirectiveEmittingEvent);
var myComp = fixture.debugElement.injector.get(MyComp);
var listener = tc.injector.get(DirectiveListeningEvent);
myComp.ctxProp = '';
expect(listener.msg).toEqual('');
myComp.ctxProp = '';
expect(listener.msg).toEqual('');
emitter.event.subscribe({
next: () => {
expect(listener.msg).toEqual('fired !');
expect(myComp.ctxProp).toEqual('fired !');
async.done();
}
});
emitter.event.subscribe({
next: () => {
expect(listener.msg).toEqual('fired !');
expect(myComp.ctxProp).toEqual('fired !');
}
});
emitter.fireEvent('fired !');
});
});
emitter.fireEvent('fired !');
}));
it('should support [()] syntax', () => {
TestBed.configureTestingModule({declarations: [MyComp, DirectiveWithTwoWayBinding]});
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const template = '<div [(control)]="ctxProp" two-way></div>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
var tc = fixture.debugElement.children[0];
var dir = tc.injector.get(DirectiveWithTwoWayBinding);
it('should support [()] syntax', async(() => {
TestBed.configureTestingModule({declarations: [MyComp, DirectiveWithTwoWayBinding]});
const template = '<div [(control)]="ctxProp" two-way></div>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
var tc = fixture.debugElement.children[0];
var dir = tc.injector.get(DirectiveWithTwoWayBinding);
fixture.debugElement.componentInstance.ctxProp = 'one';
fixture.detectChanges();
fixture.debugElement.componentInstance.ctxProp = 'one';
fixture.detectChanges();
expect(dir.control).toEqual('one');
expect(dir.control).toEqual('one');
dir.controlChange.subscribe({
next: () => {
expect(fixture.debugElement.componentInstance.ctxProp).toEqual('two');
async.done();
}
});
dir.controlChange.subscribe({
next: () => { expect(fixture.debugElement.componentInstance.ctxProp).toEqual('two'); }
});
dir.triggerChange('two');
});
});
dir.triggerChange('two');
}));
it('should support render events', () => {
TestBed.configureTestingModule({declarations: [MyComp, DirectiveListeningDomEvent]});
@ -931,8 +925,10 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should support custom interpolation', () => {
TestBed.configureTestingModule({
declarations:
[MyComp, ComponentWithCustomInterpolationA, ComponentWithCustomInterpolationB]
declarations: [
MyComp, ComponentWithCustomInterpolationA, ComponentWithCustomInterpolationB,
ComponentWithDefaultInterpolation
]
});
const template = `<div>{{ctxProp}}</div>
<cmp-with-custom-interpolation-a></cmp-with-custom-interpolation-a>
@ -1082,7 +1078,7 @@ function declareTests({useJit}: {useJit: boolean}) {
class SomeDirective {
}
@Component({selector: 'comp', template: '', directives: [SomeDirective]})
@Component({selector: 'comp', template: ''})
class SomeComponent {
}
@ -1091,18 +1087,36 @@ function declareTests({useJit}: {useJit: boolean}) {
.toThrowError(`Directive ${stringify(SomeDirective)} has no selector, please add it!`);
});
it('should use a default element name for components without selectors',
inject([Compiler, Injector], (compiler: Compiler, injector: Injector) => {
@Component({template: ''})
class SomeComponent {
}
it('should use a default element name for components without selectors', () => {
let noSelectorComponentFactory: ComponentFactory<SomeComponent>;
const compFactory = compiler.compileComponentSync(SomeComponent);
expect(compFactory.selector).toBe('ng-component');
expect(
getDOM().nodeName(compFactory.create(injector).location.nativeElement).toLowerCase())
.toEqual('ng-component');
}));
@Component({template: '----'})
class NoSelectorComponent {
}
@Component({selector: 'some-comp', template: '', entryComponents: [NoSelectorComponent]})
class SomeComponent {
constructor(componentFactoryResolver: ComponentFactoryResolver) {
// grab its own component factory
noSelectorComponentFactory =
componentFactoryResolver.resolveComponentFactory(NoSelectorComponent);
}
}
TestBed.configureTestingModule({declarations: [SomeComponent, NoSelectorComponent]});
// get the factory
TestBed.createComponent(SomeComponent);
expect(noSelectorComponentFactory.selector).toBe('ng-component');
expect(
getDOM()
.nodeName(
noSelectorComponentFactory.create(TestBed.get(Injector)).location.nativeElement)
.toLowerCase())
.toEqual('ng-component');
});
});
describe('error handling', () => {
@ -1222,7 +1236,7 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should specify a location of an error that happened during change detection (directive property)',
() => {
TestBed.configureTestingModule({declarations: [MyComp, ChildComp]});
TestBed.configureTestingModule({declarations: [MyComp, ChildComp, MyDir]});
const template = '<child-cmp [dirProp]="a.b"></child-cmp>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
@ -1414,7 +1428,8 @@ function declareTests({useJit}: {useJit: boolean}) {
}
it('should support defining views in the component decorator', () => {
TestBed.configureTestingModule({declarations: [MyComp, ComponentWithTemplate]});
TestBed.configureTestingModule(
{declarations: [MyComp, ComponentWithTemplate], imports: [CommonModule]});
const template = '<component-with-template></component-with-template>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
@ -1525,8 +1540,7 @@ class ComponentWithCustomInterpolationA {
selector: 'cmp-with-custom-interpolation-b',
template:
`<div>{**text%}</div> (<cmp-with-default-interpolation></cmp-with-default-interpolation>)`,
interpolation: ['{**', '%}'],
directives: [ComponentWithDefaultInterpolation]
interpolation: ['{**', '%}']
})
class ComponentWithCustomInterpolationB {
text = 'Custom Interpolation B';
@ -1589,8 +1603,7 @@ class EventCmp {
inputs: ['prop'],
changeDetection: ChangeDetectionStrategy.OnPush,
template:
'{{field}}<div (click)="noop()"></div><div *ngIf="true" (click)="noop()"></div><event-cmp></event-cmp>',
directives: [EventCmp, NgIf]
'{{field}}<div (click)="noop()"></div><div *ngIf="true" (click)="noop()"></div><event-cmp></event-cmp>'
})
class PushCmp {
numberOfChecks: number;
@ -1643,8 +1656,7 @@ class PushCmpWithHostEvent {
@Component({
selector: 'push-cmp-with-async',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '{{field | async}}',
pipes: [AsyncPipe]
template: '{{field | async}}'
})
class PushCmpWithAsyncPipe {
numberOfChecks: number = 0;
@ -1661,7 +1673,7 @@ class PushCmpWithAsyncPipe {
}
}
@Component({selector: 'my-comp', template: '', directives: []})
@Component({selector: 'my-comp', template: ''})
class MyComp {
ctxProp: string;
ctxNumProp: number;
@ -1681,7 +1693,6 @@ class MyComp {
selector: 'child-cmp',
inputs: ['dirProp'],
viewProviders: [MyService],
directives: [MyDir],
template: '{{ctxProp}}'
})
class ChildComp {
@ -1693,7 +1704,7 @@ class ChildComp {
}
}
@Component({selector: 'child-cmp-no-template', directives: [], template: ''})
@Component({selector: 'child-cmp-no-template', template: ''})
class ChildCompNoTemplate {
ctxProp: string = 'hello';
}
@ -1713,7 +1724,6 @@ class SomeDirectiveMissingAnnotation {}
@Component({
selector: 'cmp-with-host',
template: '<p>Component with an injected host</p>',
directives: [SomeDirective]
})
class CompWithHost {
myHost: SomeDirective;
@ -1898,7 +1908,6 @@ class ToolbarViewContainer {
@Component({
selector: 'toolbar',
template: 'TOOLBAR(<div *ngFor="let part of query" [toolbarVc]="part"></div>)',
directives: [ToolbarViewContainer, NgFor]
})
class ToolbarComponent {
@ContentChildren(ToolbarPart) query: QueryList<ToolbarPart>;
@ -2013,7 +2022,6 @@ function createParentBus(peb: EventBus) {
providers: [
{provide: EventBus, useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]}
],
directives: [forwardRef(() => ChildConsumingEventBus)],
template: `<child-consuming-event-bus></child-consuming-event-bus>`
})
class ParentProvidingEventBus {
@ -2089,7 +2097,6 @@ class DirectiveThrowingAnError {
@Component({
selector: 'component-with-template',
directives: [NgFor],
template: `No View Decorator: <div *ngFor="let item of items">{{item}}</div>`
})
class ComponentWithTemplate {

View File

@ -450,7 +450,7 @@ export function main() {
});
it('should allow to switch the order of nested components via ng-content', () => {
TestBed.configureTestingModule({declarations: [CmpA, CmpB]});
TestBed.configureTestingModule({declarations: [CmpA, CmpB, CmpD, CmpC]});
TestBed.overrideComponent(MainComp, {set: {template: `<cmp-a><cmp-b></cmp-b></cmp-a>`}});
const main = TestBed.createComponent(MainComp);
@ -555,7 +555,7 @@ class SimpleNative1 {
class SimpleNative2 {
}
@Component({selector: 'empty', template: '', directives: []})
@Component({selector: 'empty', template: ''})
class Empty {
}
@ -670,30 +670,28 @@ class CmpC {
}
@Component(
{selector: 'cmp-b', template: `<ng-content></ng-content><cmp-d></cmp-d>`, directives: [CmpD]})
@Component({selector: 'cmp-b', template: `<ng-content></ng-content><cmp-d></cmp-d>`})
class CmpB {
}
@Component(
{selector: 'cmp-a', template: `<ng-content></ng-content><cmp-c></cmp-c>`, directives: [CmpC]})
@Component({selector: 'cmp-a', template: `<ng-content></ng-content><cmp-c></cmp-c>`})
class CmpA {
}
@Component({selector: 'cmp-b11', template: `{{'b11'}}`, directives: []})
@Component({selector: 'cmp-b11', template: `{{'b11'}}`})
class CmpB11 {
}
@Component({selector: 'cmp-b12', template: `{{'b12'}}`, directives: []})
@Component({selector: 'cmp-b12', template: `{{'b12'}}`})
class CmpB12 {
}
@Component({selector: 'cmp-b21', template: `{{'b21'}}`, directives: []})
@Component({selector: 'cmp-b21', template: `{{'b21'}}`})
class CmpB21 {
}
@Component({selector: 'cmp-b22', template: `{{'b22'}}`, directives: []})
@Component({selector: 'cmp-b22', template: `{{'b22'}}`})
class CmpB22 {
}

View File

@ -6,10 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgFor, NgIf} from '@angular/common';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, ContentChild, ContentChildren, Directive, QueryList, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, asNativeElements} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
import {isPresent, stringify} from '../../src/facade/lang';
@ -748,7 +746,7 @@ class NeedsQueryDesc {
@ContentChildren(TextDirective, {descendants: true}) query: QueryList<TextDirective>;
}
@Component({selector: 'needs-query-by-ref-binding', directives: [], template: '<ng-content>'})
@Component({selector: 'needs-query-by-ref-binding', template: '<ng-content>'})
class NeedsQueryByLabel {
@ContentChildren('textLabel', {descendants: true}) query: QueryList<any>;
}
@ -758,7 +756,7 @@ class NeedsViewQueryByLabel {
@ViewChildren('textLabel') query: QueryList<any>;
}
@Component({selector: 'needs-query-by-ref-bindings', directives: [], template: '<ng-content>'})
@Component({selector: 'needs-query-by-ref-bindings', template: '<ng-content>'})
class NeedsQueryByTwoLabels {
@ContentChildren('textLabel1,textLabel2', {descendants: true}) query: QueryList<any>;
}

View File

@ -55,7 +55,6 @@ class Task {
@Component({
selector: 'example-app',
directives: [AsyncPipeExample],
template: `
<h1>AsyncPipe Example</h1>
<async-example></async-example>
@ -64,7 +63,8 @@ class Task {
export class AppCmp {
}
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
@NgModule(
{declarations: [AsyncPipeExample, AppCmp, Task], imports: [BrowserModule], bootstrap: [AppCmp]})
class AppModule {
}

View File

@ -26,7 +26,6 @@ export class DatePipeExample {
@Component({
selector: 'example-app',
directives: [DatePipeExample],
template: `
<h1>DatePipe Example</h1>
<date-example></date-example>
@ -35,10 +34,10 @@ export class DatePipeExample {
export class AppCmp {
}
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
@NgModule({declarations: [DatePipeExample, AppCmp], imports: [BrowserModule], bootstrap: [AppCmp]})
class AppModule {
}
export function main() {
platformBrowserDynamic().bootstrapModule(AppModule);
}
}

View File

@ -27,7 +27,6 @@ export class JsonPipeExample {
@Component({
selector: 'example-app',
directives: [JsonPipeExample],
template: `
<h1>JsonPipe Example</h1>
<json-example></json-example>
@ -42,4 +41,4 @@ class AppModule {
export function main() {
platformBrowserDynamic().bootstrapModule(AppModule);
}
}

View File

@ -27,7 +27,6 @@ export class LowerUpperPipeExample {
@Component({
selector: 'example-app',
directives: [LowerUpperPipeExample],
template: `
<h1>LowercasePipe &amp; UppercasePipe Example</h1>
<lowerupper-example></lowerupper-example>

View File

@ -56,7 +56,6 @@ export class CurrencyPipeExample {
@Component({
selector: 'example-app',
directives: [NumberPipeExample, PercentPipeExample, CurrencyPipeExample],
template: `
<h1>Numeric Pipe Examples</h1>
<h2>NumberPipe Example</h2>

View File

@ -41,7 +41,6 @@ export class SlicePipeListExample {
@Component({
selector: 'example-app',
directives: [SlicePipeListExample, SlicePipeStringExample],
template: `
<h1>SlicePipe Examples</h1>
<slice-list-example></slice-list-example>
@ -57,4 +56,4 @@ class AppModule {
export function main() {
platformBrowserDynamic().bootstrapModule(AppModule);
}
}

View File

@ -11,7 +11,7 @@ import {Attribute, Component, Directive, Pipe} from '@angular/core';
class CustomDirective {};
// #docregion component
@Component({selector: 'greet', template: 'Hello {{name}}!', directives: [CustomDirective]})
@Component({selector: 'greet', template: 'Hello {{name}}!'})
class Greet {
name: string = 'World';
}

View File

@ -8,8 +8,7 @@
import {ResourceLoader, UrlResolver} from '@angular/compiler';
import {BaseException, Component} from '@angular/core';
import {TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {TestBed, async, fakeAsync, tick} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/matchers';
import {CachedResourceLoader} from '../../src/resource_loader/resource_loader_cache';
@ -43,28 +42,30 @@ export function main() {
}).toThrowError('CachedResourceLoader: Template cache was not found in $templateCache.');
});
it('should resolve the Promise with the cached file content on success',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should resolve the Promise with the cached file content on success', async(() => {
setTemplateCache({'test.html': '<div>Hello</div>'});
resourceLoader = new CachedResourceLoader();
resourceLoader.get('test.html').then((text) => {
expect(text).toEqual('<div>Hello</div>');
async.done();
});
resourceLoader.get('test.html').then((text) => { expect(text).toBe('<div>Hello</div>'); });
}));
it('should reject the Promise on failure',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should reject the Promise on failure', async(() => {
resourceLoader = new CachedResourceLoader();
resourceLoader.get('unknown.html')
.then((text) => { throw new BaseException('Not expected to succeed.'); })
.catch((error) => { async.done(); });
.catch((error) => {/** success */});
}));
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
fakeAsync(() => {
TestBed.configureTestingModule({declarations: [TestComponent]});
TestBed.compileComponents();
tick();
let fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
// This should initialize the fixture.
tick();
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
}));
});

View File

@ -6,10 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgIf} from '@angular/common';
import {Component, ComponentRef, Injectable, Injector, ReflectiveInjector, getPlatform} from '@angular/core';
import {Component, ComponentRef, Injectable, Injector} from '@angular/core';
import {DebugDomRootRenderer} from '@angular/core/src/debug/debug_renderer';
import {ViewMetadata} from '@angular/core/src/metadata/view';
import {RootRenderer} from '@angular/core/src/render/api';
import {TestBed} from '@angular/core/testing';
import {platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
@ -206,7 +204,7 @@ export function main() {
}
@Component({selector: 'my-comp', directives: []})
@Component({selector: 'my-comp'})
@Injectable()
class MyComp2 {
ctxProp: string;

View File

@ -24,7 +24,7 @@ function writeBody(html: string): any {
class MyServerApp {
}
@NgModule({imports: [ServerModule], declarations: [MyServerApp], bootstrap: [MyServerApp]})
@NgModule({declarations: [MyServerApp], imports: [ServerModule], bootstrap: [MyServerApp]})
class ExampleModule {
}

View File

@ -57,6 +57,6 @@ export class HelloCmp {
changeGreeting(): void { this.greeting = 'howdy'; }
}
@NgModule({bootstrap: [HelloCmp], declarations: [HelloCmp, RedDec], imports: [BrowserModule]})
@NgModule({declarations: [HelloCmp, RedDec], bootstrap: [HelloCmp], imports: [BrowserModule]})
class ExampleModule {
}

View File

@ -158,7 +158,7 @@ class ReactiveForms {
@NgModule({
bootstrap: [ReactiveForms],
declarations: [ReactiveForms, ShowError],
declarations: [ShowError, ReactiveForms],
imports: [BrowserModule, ReactiveFormsModule]
})
class ExampleModule {

View File

@ -18,12 +18,11 @@ export function main() {
@Component({
selector: 'relative-app',
directives: [MyCmp],
template: `component = <my-cmp></my-cmp>`,
})
export class RelativeApp {
}
@NgModule({declarations: [RelativeApp], bootstrap: [RelativeApp], imports: [BrowserModule]})
@NgModule({declarations: [RelativeApp, MyCmp], bootstrap: [RelativeApp], imports: [BrowserModule]})
class ExampleModule {
}

View File

@ -9,7 +9,7 @@
import {NgFor, NgIf} from '@angular/common';
import {Component, Directive, Host, NgModule} from '@angular/core';
import {isPresent, print} from '@angular/core/src/facade/lang';
import {FORM_DIRECTIVES, FormGroup, NG_VALIDATORS, NgControl, NgForm, Validators} from '@angular/forms';
import {FormGroup, FormsModule, NG_VALIDATORS, NgControl, NgForm, Validators} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
@ -71,8 +71,7 @@ class CreditCardValidator {
inputs: ['controlPath: control', 'errorTypes: errors'],
template: `
<span *ngIf="errorMessage !== null">{{errorMessage}}</span>
`,
directives: [NgIf]
`
})
class ShowError {
formDir: any /** TODO #9100 */;
@ -157,8 +156,7 @@ class ShowError {
<button type="submit" [disabled]="!f.form.valid">Submit</button>
</form>
`,
directives: [FORM_DIRECTIVES, NgFor, CreditCardValidator, ShowError]
`
})
class TemplateDrivenForms {
model = new CheckoutModel();
@ -170,9 +168,9 @@ class TemplateDrivenForms {
}
}
@NgModule({
declarations: [TemplateDrivenForms],
declarations: [TemplateDrivenForms, CreditCardValidator, ShowError],
bootstrap: [TemplateDrivenForms],
imports: [BrowserModule]
imports: [BrowserModule, FormsModule]
})
class ExampleModule {
}

View File

@ -46,12 +46,7 @@ export class RedDec {
// context of the HelloCmp class below.
template: `<div class="greeting">{{greeting}} <span red>world</span>!</div>
<button class="changeButton" (click)="changeGreeting()">change greeting</button>
<div (keydown)="onKeyDown($event)" class="sample-area" tabindex="0">{{lastKey}}</div><br>`,
// All directives used in the template need to be specified. This allows for
// modularity (RedDec can only be used in this template)
// and better tooling (the template can be invalidated if the attribute is
// misspelled).
directives: [RedDec]
<div (keydown)="onKeyDown($event)" class="sample-area" tabindex="0">{{lastKey}}</div><br>`
})
export class HelloCmp {
greeting: string;

View File

@ -7,12 +7,13 @@
*/
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {WorkerAppModule} from '@angular/platform-browser';
import {platformWorkerAppDynamic} from '@angular/platform-browser-dynamic';
import {TodoApp} from './index_common';
@NgModule({imports: [WorkerAppModule], bootstrap: [TodoApp], declarations: [TodoApp]})
@NgModule({imports: [WorkerAppModule, FormsModule], bootstrap: [TodoApp], declarations: [TodoApp]})
class ExampleModule {
}

View File

@ -6,18 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgFor} from '@angular/common';
import {Component} from '@angular/core';
import {FORM_DIRECTIVES} from '@angular/forms';
import {Store, Todo, TodoFactory} from './services/TodoStore';
@Component({
selector: 'todo-app',
viewProviders: [Store, TodoFactory],
templateUrl: 'todo.html',
directives: [NgFor, FORM_DIRECTIVES]
})
@Component({selector: 'todo-app', viewProviders: [Store, TodoFactory], templateUrl: 'todo.html'})
export class TodoApp {
todoEdit: Todo = null;
inputValue: string;

View File

@ -21,8 +21,7 @@ import {Zippy} from './app/zippy';
<ul>
<li *ngFor="let log of logs">{{log}}</li>
</ul>
`,
directives: [Zippy]
`
})
class ZippyApp {
logs: string[] = [];
@ -30,10 +29,10 @@ class ZippyApp {
pushLog(log: string) { this.logs.push(log); }
}
@NgModule({declarations: [ZippyApp], bootstrap: [ZippyApp], imports: [BrowserModule]})
@NgModule({declarations: [ZippyApp, Zippy], bootstrap: [ZippyApp], imports: [BrowserModule]})
class ExampleModule {
}
export function main() {
platformBrowserDynamic().bootstrapModule(ExampleModule);
}
}