Remove TCB (#10900)

* refactor(webworker): change tests not to use TestComponentBuilder

* refactor(core): change tests not to use TestComponentBuilder
This commit is contained in:
Victor Savkin
2016-08-17 15:05:22 -07:00
committed by Kara
parent 3009be8d6e
commit 4be863c223
2 changed files with 135 additions and 184 deletions

View File

@ -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: `<simple [marker]="'1'"></simple><simple [marker]="'2'"></simple>`,
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: `<simple #child></simple>`, 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: `<simple [marker]="'1'"></simple><simple [marker]="'2'"></simple>`}});
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: `<simple #child></simple>`}});
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: `<simple></simple><simple></simple>`, 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: `<simple #child1></simple><simple #child2></simple>`,
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: `<simple></simple><simple></simple>`}});
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: `<simple #child1></simple><simple #child2></simple>`}});
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<Simple>;
}
@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<ElementRef>;