diff --git a/modules/@angular/core/test/metadata/di_spec.ts b/modules/@angular/core/test/metadata/di_spec.ts index 2dfbf0f19f..fbf7adcd10 100644 --- a/modules/@angular/core/test/metadata/di_spec.ts +++ b/modules/@angular/core/test/metadata/di_spec.ts @@ -7,76 +7,66 @@ */ import {Component, Directive, ElementRef, Input, QueryList, ViewChild, ViewChildren} from '@angular/core'; -import {ViewMetadata} from '@angular/core/src/metadata/view'; -import {AsyncTestCompleter, TestComponentBuilder, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {TestBed} from '@angular/core/testing'; export function main() { describe('ViewChild', () => { - it('should support type selector', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView( - ViewChildTypeSelectorComponent, new ViewMetadata({ - template: ``, - directives: [Simple] - })) - .createAsync(ViewChildTypeSelectorComponent) - .then((view) => { - view.detectChanges(); - expect(view.componentInstance.child).toBeDefined(); - expect(view.componentInstance.child.marker).toBe('1'); - async.done(); - }); - })); - it('should support string selector', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView( - ViewChildStringSelectorComponent, - new ViewMetadata({template: ``, directives: [Simple]})) - .createAsync(ViewChildStringSelectorComponent) - .then((view) => { - view.detectChanges(); - expect(view.componentInstance.child).toBeDefined(); - async.done(); - }); - })); + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ViewChildTypeSelectorComponent, ViewChildStringSelectorComponent, Simple] + }); + }); + + it('should support type selector', () => { + TestBed.overrideComponent( + ViewChildTypeSelectorComponent, + {set: {template: ``}}); + const view = TestBed.createComponent(ViewChildTypeSelectorComponent); + + view.detectChanges(); + expect(view.componentInstance.child).toBeDefined(); + expect(view.componentInstance.child.marker).toBe('1'); + }); + + it('should support string selector', () => { + TestBed.overrideComponent( + ViewChildStringSelectorComponent, {set: {template: ``}}); + const view = TestBed.createComponent(ViewChildStringSelectorComponent); + + view.detectChanges(); + expect(view.componentInstance.child).toBeDefined(); + }); }); + describe('ViewChildren', () => { - it('should support type selector', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView( - ViewChildrenTypeSelectorComponent, - new ViewMetadata( - {template: ``, directives: [Simple]})) - .createAsync(ViewChildrenTypeSelectorComponent) - .then((view) => { - view.detectChanges(); - expect(view.componentInstance.children).toBeDefined(); - expect(view.componentInstance.children.length).toBe(2); - async.done(); - }); - })); - it('should support string selector', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView(ViewChildrenStringSelectorComponent, new ViewMetadata({ - template: ``, - directives: [Simple] - })) - .createAsync(ViewChildrenStringSelectorComponent) - .then((view) => { - view.detectChanges(); - expect(view.componentInstance.children).toBeDefined(); - expect(view.componentInstance.children.length).toBe(2); - async.done(); - }); - })); + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: + [ViewChildrenTypeSelectorComponent, ViewChildrenStringSelectorComponent, Simple] + }); + }); + + it('should support type selector', () => { + TestBed.overrideComponent( + ViewChildrenTypeSelectorComponent, + {set: {template: ``}}); + + const view = TestBed.createComponent(ViewChildrenTypeSelectorComponent); + view.detectChanges(); + expect(view.componentInstance.children).toBeDefined(); + expect(view.componentInstance.children.length).toBe(2); + }); + + it('should support string selector', () => { + TestBed.overrideComponent( + ViewChildrenStringSelectorComponent, + {set: {template: ``}}); + const view = TestBed.createComponent(ViewChildrenStringSelectorComponent); + view.detectChanges(); + expect(view.componentInstance.children).toBeDefined(); + expect(view.componentInstance.children.length).toBe(2); + + }); }); } @@ -86,22 +76,22 @@ class Simple { @Input() marker: string; } -@Component({selector: 'view-child-type-selector'}) +@Component({selector: 'view-child-type-selector', template: ''}) class ViewChildTypeSelectorComponent { @ViewChild(Simple) child: Simple; } -@Component({selector: 'view-child-string-selector'}) +@Component({selector: 'view-child-string-selector', template: ''}) class ViewChildStringSelectorComponent { @ViewChild('child') child: ElementRef; } -@Component({selector: 'view-children-type-selector'}) +@Component({selector: 'view-children-type-selector', template: ''}) class ViewChildrenTypeSelectorComponent { @ViewChildren(Simple) children: QueryList; } -@Component({selector: 'view-child-string-selector'}) +@Component({selector: 'view-child-string-selector', template: ''}) class ViewChildrenStringSelectorComponent { // Allow comma separated selector (with spaces). @ViewChildren('child1 , child2') children: QueryList; diff --git a/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts b/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts index d891261f51..01d7a4cdac 100644 --- a/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts +++ b/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts @@ -12,7 +12,6 @@ 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 {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal'; import {platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DomRootRenderer, DomRootRenderer_} from '@angular/platform-browser/src/dom/dom_renderer'; @@ -81,6 +80,7 @@ export function main() { workerRenderStore = new RenderStore(); TestBed.configureTestingModule({ + declarations: [MyComp2], providers: [ Serializer, {provide: RenderStore, useValue: workerRenderStore}, { provide: RootRenderer, @@ -104,142 +104,103 @@ export function main() { return (componentRef.hostView).internalView.renderer; } - it('should update text nodes', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView(MyComp2, new ViewMetadata({template: '
{{ctxProp}}
'})) - .createAsync(MyComp2) - .then((fixture) => { - var renderEl = getRenderElement(fixture.debugElement.nativeElement); - expect(renderEl).toHaveText(''); + it('should update text nodes', () => { + TestBed.overrideComponent(MyComp2, {set: {template: '
{{ctxProp}}
'}}); + const fixture = TestBed.createComponent(MyComp2); - fixture.debugElement.componentInstance.ctxProp = 'Hello World!'; - fixture.detectChanges(); - expect(renderEl).toHaveText('Hello World!'); - async.done(); + var renderEl = getRenderElement(fixture.debugElement.nativeElement); + expect(renderEl).toHaveText(''); - }); - })); + fixture.debugElement.componentInstance.ctxProp = 'Hello World!'; + fixture.detectChanges(); + expect(renderEl).toHaveText('Hello World!'); + }); it('should update any element property/attributes/class/style(s) independent of the compilation on the root element and other elements', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView( - MyComp2, - new ViewMetadata({template: ''})) - .createAsync(MyComp2) - .then((fixture) => { - var checkSetters = - (componentRef: any /** TODO #9100 */, workerEl: any /** TODO #9100 */) => { - var renderer = getRenderer(componentRef); - var el = getRenderElement(workerEl); - renderer.setElementProperty(workerEl, 'tabIndex', 1); - expect((el).tabIndex).toEqual(1); + () => { + TestBed.overrideComponent( + MyComp2, {set: {template: ''}}); + const fixture = TestBed.createComponent(MyComp2); - renderer.setElementClass(workerEl, 'a', true); - expect(getDOM().hasClass(el, 'a')).toBe(true); - renderer.setElementClass(workerEl, 'a', false); - expect(getDOM().hasClass(el, 'a')).toBe(false); + var checkSetters = + (componentRef: any /** TODO #9100 */, workerEl: any /** TODO #9100 */) => { + var renderer = getRenderer(componentRef); + var el = getRenderElement(workerEl); + renderer.setElementProperty(workerEl, 'tabIndex', 1); + expect((el).tabIndex).toEqual(1); - renderer.setElementStyle(workerEl, 'width', '10px'); - expect(getDOM().getStyle(el, 'width')).toEqual('10px'); - renderer.setElementStyle(workerEl, 'width', null); - expect(getDOM().getStyle(el, 'width')).toEqual(''); + renderer.setElementClass(workerEl, 'a', true); + expect(getDOM().hasClass(el, 'a')).toBe(true); + renderer.setElementClass(workerEl, 'a', false); + expect(getDOM().hasClass(el, 'a')).toBe(false); - renderer.setElementAttribute(workerEl, 'someattr', 'someValue'); - expect(getDOM().getAttribute(el, 'someattr')).toEqual('someValue'); - }; + renderer.setElementStyle(workerEl, 'width', '10px'); + expect(getDOM().getStyle(el, 'width')).toEqual('10px'); + renderer.setElementStyle(workerEl, 'width', null); + expect(getDOM().getStyle(el, 'width')).toEqual(''); - // root element - checkSetters(fixture.componentRef, fixture.debugElement.nativeElement); - // nested elements - checkSetters( - fixture.componentRef, fixture.debugElement.children[0].nativeElement); + renderer.setElementAttribute(workerEl, 'someattr', 'someValue'); + expect(getDOM().getAttribute(el, 'someattr')).toEqual('someValue'); + }; - async.done(); - }); - })); + // root element + checkSetters(fixture.componentRef, fixture.debugElement.nativeElement); + // nested elements + checkSetters(fixture.componentRef, fixture.debugElement.children[0].nativeElement); + }); - it('should update any template comment property/attributes', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var tpl = ''; - tcb.overrideView(MyComp2, new ViewMetadata({template: tpl, directives: [NgIf]})) + it('should update any template comment property/attributes', () => { - .createAsync(MyComp2) - .then((fixture) => { - (fixture.debugElement.componentInstance).ctxBoolProp = true; - fixture.detectChanges(); - var el = getRenderElement(fixture.debugElement.nativeElement); - expect(getDOM().getInnerHTML(el)).toContain('"ng-reflect-ng-if": "true"'); - async.done(); - }); - })); + TestBed.overrideComponent( + MyComp2, {set: {template: ''}}); + const fixture = TestBed.createComponent(MyComp2); - it('should add and remove fragments', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView(MyComp2, new ViewMetadata({ - template: '', - directives: [NgIf] - })) - .createAsync(MyComp2) - .then((fixture) => { + (fixture.debugElement.componentInstance).ctxBoolProp = true; + fixture.detectChanges(); + var el = getRenderElement(fixture.debugElement.nativeElement); + expect(getDOM().getInnerHTML(el)).toContain('"ng-reflect-ng-if": "true"'); + }); - var rootEl = getRenderElement(fixture.debugElement.nativeElement); - expect(rootEl).toHaveText(''); + it('should add and remove fragments', () => { + TestBed.overrideComponent( + MyComp2, {set: {template: ''}}); + const fixture = TestBed.createComponent(MyComp2); - fixture.debugElement.componentInstance.ctxBoolProp = true; - fixture.detectChanges(); - expect(rootEl).toHaveText('hello'); + var rootEl = getRenderElement(fixture.debugElement.nativeElement); + expect(rootEl).toHaveText(''); - fixture.debugElement.componentInstance.ctxBoolProp = false; - fixture.detectChanges(); - expect(rootEl).toHaveText(''); + fixture.debugElement.componentInstance.ctxBoolProp = true; + fixture.detectChanges(); + expect(rootEl).toHaveText('hello'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.ctxBoolProp = false; + fixture.detectChanges(); + expect(rootEl).toHaveText(''); + }); if (getDOM().supportsDOMEvents()) { - it('should call actions on the element', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView(MyComp2, new ViewMetadata({template: ''})) - .createAsync(MyComp2) - .then((fixture) => { - var el = fixture.debugElement.children[0]; - getRenderer(fixture.componentRef) - .invokeElementMethod(el.nativeElement, 'setAttribute', ['a', 'b']); + it('should call actions on the element', () => { + TestBed.overrideComponent(MyComp2, {set: {template: ''}}); + const fixture = TestBed.createComponent(MyComp2); + var el = fixture.debugElement.children[0]; + getRenderer(fixture.componentRef).invokeElementMethod(el.nativeElement, 'setAttribute', [ + 'a', 'b' + ]); - expect(getDOM().getAttribute(getRenderElement(el.nativeElement), 'a')) - .toEqual('b'); - async.done(); - }); - })); + expect(getDOM().getAttribute(getRenderElement(el.nativeElement), 'a')).toEqual('b'); - it('should listen to events', - inject( - [TestComponentBuilder, AsyncTestCompleter], - (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideView( - MyComp2, new ViewMetadata({template: ''})) - .createAsync(MyComp2) - .then((fixture) => { - var el = fixture.debugElement.children[0]; - dispatchEvent(getRenderElement(el.nativeElement), 'change'); - expect(fixture.componentInstance.ctxNumProp).toBe(1); + }); - fixture.destroy(); + it('should listen to events', () => { + TestBed.overrideComponent(MyComp2, {set: {template: ''}}); + const fixture = TestBed.createComponent(MyComp2); - async.done(); - }); - })); + var el = fixture.debugElement.children[0]; + dispatchEvent(getRenderElement(el.nativeElement), 'change'); + expect(fixture.componentInstance.ctxNumProp).toBe(1); + + fixture.destroy(); + }); } }); }