chore(test): rename RootTestComponent to ComponentFixture

BREAKING CHANGE:

Before:

```
testComponentBuilder.createAsync(MyComponent).then(root: RootTestComponent => {
}
```

After:

```
testComponentBuilder.createAsync(MyComponent).then(fixture: ComponentFixture => {
}
```

Closes #4711
This commit is contained in:
Julie Ralph 2015-10-31 09:50:19 -07:00
parent a16214c614
commit 686457890d
25 changed files with 1128 additions and 1121 deletions

View File

@ -22,14 +22,14 @@ import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DebugElement, DebugElement_} from 'angular2/src/core/debug/debug_element';
export abstract class RootTestComponent {
export abstract class ComponentFixture {
debugElement: DebugElement;
abstract detectChanges(): void;
abstract destroy(): void;
}
export class RootTestComponent_ extends RootTestComponent {
export class ComponentFixture_ extends ComponentFixture {
/** @internal */
_componentRef: ComponentRef;
/** @internal */
@ -53,7 +53,7 @@ export class RootTestComponent_ extends RootTestComponent {
var _nextRootElementId = 0;
/**
* Builds a RootTestComponent for use in component level tests.
* Builds a ComponentFixture for use in component level tests.
*/
@Injectable()
export class TestComponentBuilder {
@ -186,11 +186,11 @@ export class TestComponentBuilder {
}
/**
* Builds and returns a RootTestComponent.
* Builds and returns a ComponentFixture.
*
* @return {Promise<RootTestComponent>}
* @return {Promise<ComponentFixture>}
*/
createAsync(rootComponentType: Type): Promise<RootTestComponent> {
createAsync(rootComponentType: Type): Promise<ComponentFixture> {
var mockDirectiveResolver = this._injector.get(DirectiveResolver);
var mockViewResolver = this._injector.get(ViewResolver);
this._viewOverrides.forEach((view, type) => mockViewResolver.setView(type, view));
@ -220,6 +220,6 @@ export class TestComponentBuilder {
return this._injector.get(DynamicComponentLoader)
.loadAsRoot(rootComponentType, `#${rootElId}`, this._injector)
.then((componentRef) => { return new RootTestComponent_(componentRef); });
.then((componentRef) => { return new ComponentFixture_(componentRef); });
}
}

View File

@ -137,14 +137,14 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
.then((componentFixture) => {
componentFixture.detectChanges();
var childEls = rootTestComponent.debugElement.children;
var childEls = componentFixture.debugElement.children;
// The root is a lone component, and has no children in the light dom.
expect(childEls.length).toEqual(0);
var rootCompChildren = rootTestComponent.debugElement.componentViewChildren;
var rootCompChildren = componentFixture.debugElement.componentViewChildren;
// The root component has 4 elements in its shadow view.
expect(rootCompChildren.length).toEqual(4);
expect(DOM.hasClass(rootCompChildren[0].nativeElement, 'parent')).toBe(true);
@ -185,10 +185,10 @@ export function main() {
it('should list child elements within viewports',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(UsingFor).then((rootTestComponent) => {
rootTestComponent.detectChanges();
tcb.createAsync(UsingFor).then((componentFixture) => {
componentFixture.detectChanges();
var childEls = rootTestComponent.debugElement.componentViewChildren;
var childEls = componentFixture.debugElement.componentViewChildren;
// TODO should this count include the <template> element?
expect(childEls.length).toEqual(5);
@ -203,10 +203,10 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
.then((componentFixture) => {
componentFixture.detectChanges();
var childTestEls = rootTestComponent.debugElement.queryAll(By.directive(MessageDir));
var childTestEls = componentFixture.debugElement.queryAll(By.directive(MessageDir));
expect(childTestEls.length).toBe(4);
expect(DOM.hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true);
@ -221,10 +221,10 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
.then((componentFixture) => {
componentFixture.detectChanges();
var parentEl = rootTestComponent.debugElement.componentViewChildren[0];
var parentEl = componentFixture.debugElement.componentViewChildren[0];
var childTestEls = parentEl.queryAll(By.directive(MessageDir), Scope.light);
@ -239,11 +239,11 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
.then((componentFixture) => {
componentFixture.detectChanges();
var childTestEls =
rootTestComponent.debugElement.queryAll(By.directive(MessageDir), Scope.view);
componentFixture.debugElement.queryAll(By.directive(MessageDir), Scope.view);
expect(childTestEls.length).toBe(2);
expect(DOM.hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true);
@ -257,10 +257,10 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
.then((componentFixture) => {
componentFixture.detectChanges();
expect(rootTestComponent.debugElement.componentViewChildren[0].inject(Logger).log)
expect(componentFixture.debugElement.componentViewChildren[0].inject(Logger).log)
.toEqual(['parent', 'nestedparent', 'child', 'nestedchild']);
async.done();
@ -271,19 +271,19 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(EventsComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
.then((componentFixture) => {
componentFixture.detectChanges();
expect(rootTestComponent.debugElement.componentInstance.clicked).toBe(false);
expect(rootTestComponent.debugElement.componentInstance.customed).toBe(false);
expect(componentFixture.debugElement.componentInstance.clicked).toBe(false);
expect(componentFixture.debugElement.componentInstance.customed).toBe(false);
rootTestComponent.debugElement.componentViewChildren[0].triggerEventHandler(
componentFixture.debugElement.componentViewChildren[0].triggerEventHandler(
'click', <Event>{});
expect(rootTestComponent.debugElement.componentInstance.clicked).toBe(true);
expect(componentFixture.debugElement.componentInstance.clicked).toBe(true);
rootTestComponent.debugElement.componentViewChildren[1].triggerEventHandler(
componentFixture.debugElement.componentViewChildren[1].triggerEventHandler(
'myevent', <Event>{});
expect(rootTestComponent.debugElement.componentInstance.customed).toBe(true);
expect(componentFixture.debugElement.componentInstance.customed).toBe(true);
async.done();
});

View File

@ -34,8 +34,8 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '<div some-dir></div>')
.createAsync(MyComp)
.then((rootTestComponent) => {
expect(inspectNativeElement(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
expect(inspectNativeElement(componentFixture.debugElement.nativeElement)
.componentInstance)
.toBeAnInstanceOf(MyComp);
@ -47,10 +47,9 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp)
.then((rootTestComponent) => {
rootTestComponent.destroy();
expect(inspectNativeElement(rootTestComponent.debugElement.nativeElement))
.toBe(null);
.then((componentFixture) => {
componentFixture.destroy();
expect(inspectNativeElement(componentFixture.debugElement.nativeElement)).toBe(null);
async.done();
});
@ -62,8 +61,8 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp)
.then((rootTestComponent) => {
expect(global['ng']['probe'](rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
expect(global['ng']['probe'](componentFixture.debugElement.nativeElement)
.componentInstance)
.toBeAnInstanceOf(MyComp);

View File

@ -1,5 +1,5 @@
import {
RootTestComponent,
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
@ -19,9 +19,9 @@ import {Component, View, NgFor, provide} from 'angular2/angular2';
import {NgClass} from 'angular2/src/core/directives/ng_class';
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
function detectChangesAndCheck(rootTC: RootTestComponent, classes: string, elIndex: number = 0) {
rootTC.detectChanges();
expect(rootTC.debugElement.componentViewChildren[elIndex].nativeElement.className)
function detectChangesAndCheck(fixture: ComponentFixture, classes: string, elIndex: number = 0) {
fixture.detectChanges();
expect(fixture.debugElement.componentViewChildren[elIndex].nativeElement.className)
.toEqual(classes);
}
@ -36,12 +36,12 @@ export function main() {
var template = '<div *ng-for="var item of items" [ng-class]="item"></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [['0']];
rootTC.detectChanges();
rootTC.debugElement.componentInstance.items = [['1']];
.then((fixture) => {
fixture.debugElement.componentInstance.items = [['0']];
fixture.detectChanges();
fixture.debugElement.componentInstance.items = [['1']];
detectChangesAndCheck(rootTC, '1', 1);
detectChangesAndCheck(fixture, '1', 1);
async.done();
});
@ -57,8 +57,8 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
async.done();
});
}));
@ -70,8 +70,8 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo-bar fooBar');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo-bar fooBar');
async.done();
});
}));
@ -82,11 +82,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.condition = false;
detectChangesAndCheck(rootTC, 'bar');
fixture.debugElement.componentInstance.condition = false;
detectChangesAndCheck(fixture, 'bar');
async.done();
});
@ -98,17 +98,17 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'foo bar');
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(fixture, 'foo bar');
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'baz', true);
detectChangesAndCheck(rootTC, 'foo bar baz');
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'baz', true);
detectChangesAndCheck(fixture, 'foo bar baz');
StringMapWrapper.delete(rootTC.debugElement.componentInstance.objExpr, 'bar');
detectChangesAndCheck(rootTC, 'foo baz');
StringMapWrapper.delete(fixture.debugElement.componentInstance.objExpr, 'bar');
detectChangesAndCheck(fixture, 'foo baz');
async.done();
});
@ -120,14 +120,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.objExpr = {foo: true, bar: true};
detectChangesAndCheck(rootTC, 'foo bar');
fixture.debugElement.componentInstance.objExpr = {foo: true, bar: true};
detectChangesAndCheck(fixture, 'foo bar');
rootTC.debugElement.componentInstance.objExpr = {baz: true};
detectChangesAndCheck(rootTC, 'baz');
fixture.debugElement.componentInstance.objExpr = {baz: true};
detectChangesAndCheck(fixture, 'baz');
async.done();
});
@ -139,14 +139,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, '');
fixture.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(fixture, '');
rootTC.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true};
detectChangesAndCheck(rootTC, 'bar');
fixture.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true};
detectChangesAndCheck(fixture, 'bar');
async.done();
});
@ -161,8 +161,8 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo bar foo-bar fooBar');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar');
async.done();
});
}));
@ -173,18 +173,18 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
var arrExpr: string[] = rootTC.debugElement.componentInstance.arrExpr;
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
var arrExpr: string[] = fixture.debugElement.componentInstance.arrExpr;
detectChangesAndCheck(fixture, 'foo');
arrExpr.push('bar');
detectChangesAndCheck(rootTC, 'foo bar');
detectChangesAndCheck(fixture, 'foo bar');
arrExpr[1] = 'baz';
detectChangesAndCheck(rootTC, 'foo baz');
detectChangesAndCheck(fixture, 'foo baz');
ListWrapper.remove(rootTC.debugElement.componentInstance.arrExpr, 'baz');
detectChangesAndCheck(rootTC, 'foo');
ListWrapper.remove(fixture.debugElement.componentInstance.arrExpr, 'baz');
detectChangesAndCheck(fixture, 'foo');
async.done();
});
@ -196,11 +196,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.arrExpr = ['bar'];
detectChangesAndCheck(rootTC, 'bar');
fixture.debugElement.componentInstance.arrExpr = ['bar'];
detectChangesAndCheck(fixture, 'bar');
async.done();
});
@ -212,11 +212,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.arrExpr = ['bar'];
detectChangesAndCheck(rootTC, 'foo bar');
fixture.debugElement.componentInstance.arrExpr = ['bar'];
detectChangesAndCheck(fixture, 'foo bar');
async.done();
});
@ -228,10 +228,10 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
.then((fixture) => {
rootTC.debugElement.componentInstance.arrExpr = ['', ' '];
detectChangesAndCheck(rootTC, 'foo');
fixture.debugElement.componentInstance.arrExpr = ['', ' '];
detectChangesAndCheck(fixture, 'foo');
async.done();
});
@ -243,10 +243,10 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
.then((fixture) => {
rootTC.debugElement.componentInstance.arrExpr = [' bar '];
detectChangesAndCheck(rootTC, 'foo bar');
fixture.debugElement.componentInstance.arrExpr = [' bar '];
detectChangesAndCheck(fixture, 'foo bar');
async.done();
});
@ -261,16 +261,16 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
.then((fixture) => {
var setExpr = new Set<string>();
setExpr.add('bar');
rootTC.debugElement.componentInstance.setExpr = setExpr;
detectChangesAndCheck(rootTC, 'bar');
fixture.debugElement.componentInstance.setExpr = setExpr;
detectChangesAndCheck(fixture, 'bar');
setExpr = new Set<string>();
setExpr.add('baz');
rootTC.debugElement.componentInstance.setExpr = setExpr;
detectChangesAndCheck(rootTC, 'baz');
fixture.debugElement.componentInstance.setExpr = setExpr;
detectChangesAndCheck(fixture, 'baz');
async.done();
});
@ -284,8 +284,8 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo bar foo-bar fooBar');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar');
async.done();
});
}));
@ -296,15 +296,15 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.strExpr = 'foo bar';
detectChangesAndCheck(rootTC, 'foo bar');
fixture.debugElement.componentInstance.strExpr = 'foo bar';
detectChangesAndCheck(fixture, 'foo bar');
rootTC.debugElement.componentInstance.strExpr = 'baz';
detectChangesAndCheck(rootTC, 'baz');
fixture.debugElement.componentInstance.strExpr = 'baz';
detectChangesAndCheck(fixture, 'baz');
async.done();
});
@ -316,11 +316,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.strExpr = null;
detectChangesAndCheck(rootTC, '');
fixture.debugElement.componentInstance.strExpr = null;
detectChangesAndCheck(fixture, '');
async.done();
});
@ -332,11 +332,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'foo');
rootTC.debugElement.componentInstance.strExpr = null;
detectChangesAndCheck(rootTC, 'foo');
fixture.debugElement.componentInstance.strExpr = null;
detectChangesAndCheck(fixture, 'foo');
async.done();
});
@ -348,9 +348,9 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.strExpr = '';
detectChangesAndCheck(rootTC, 'foo');
.then((fixture) => {
fixture.debugElement.componentInstance.strExpr = '';
detectChangesAndCheck(fixture, 'foo');
async.done();
});
@ -366,15 +366,15 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'init foo bar');
.then((fixture) => {
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(fixture, 'init foo bar');
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, 'init bar');
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(fixture, 'init bar');
rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, 'init foo');
fixture.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(fixture, 'init foo');
async.done();
});
@ -386,15 +386,15 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, `init foo bar`);
.then((fixture) => {
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(fixture, `init foo bar`);
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, `init bar`);
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(fixture, `init bar`);
rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, `init foo`);
fixture.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(fixture, `init foo`);
async.done();
});
@ -406,15 +406,15 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, `init foo bar`);
.then((fixture) => {
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(fixture, `init foo bar`);
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, `init bar`);
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(fixture, `init bar`);
rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, `init foo`);
fixture.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(fixture, `init foo`);
async.done();
});
@ -427,17 +427,17 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'init foo baz');
.then((fixture) => {
detectChangesAndCheck(fixture, 'init foo baz');
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'init foo baz bar');
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(fixture, 'init foo baz bar');
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, 'init baz bar');
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(fixture, 'init baz bar');
rootTC.debugElement.componentInstance.condition = false;
detectChangesAndCheck(rootTC, 'init bar');
fixture.debugElement.componentInstance.condition = false;
detectChangesAndCheck(fixture, 'init bar');
async.done();
});
@ -449,17 +449,17 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
detectChangesAndCheck(rootTC, 'init foo');
.then((fixture) => {
detectChangesAndCheck(fixture, 'init foo');
StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'init foo bar');
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(fixture, 'init foo bar');
rootTC.debugElement.componentInstance.strExpr = 'baz';
detectChangesAndCheck(rootTC, 'init bar baz foo');
fixture.debugElement.componentInstance.strExpr = 'baz';
detectChangesAndCheck(fixture, 'init bar baz foo');
rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, 'init baz');
fixture.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(fixture, 'init baz');
async.done();
});

View File

@ -29,9 +29,9 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('1;2;');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('1;2;');
async.done();
});
}));
@ -40,13 +40,13 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
.then((fixture) => {
fixture.detectChanges();
(<number[]>rootTC.debugElement.componentInstance.items).push(3);
rootTC.detectChanges();
(<number[]>fixture.debugElement.componentInstance.items).push(3);
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('1;2;3;');
expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;');
async.done();
});
}));
@ -55,13 +55,13 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
.then((fixture) => {
fixture.detectChanges();
ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 1);
rootTC.detectChanges();
ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 1);
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('1;');
expect(fixture.debugElement.nativeElement).toHaveText('1;');
async.done();
});
}));
@ -70,14 +70,14 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
.then((fixture) => {
fixture.detectChanges();
ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 0);
(<number[]>rootTC.debugElement.componentInstance.items).push(1);
rootTC.detectChanges();
ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 0);
(<number[]>fixture.debugElement.componentInstance.items).push(1);
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('2;1;');
expect(fixture.debugElement.nativeElement).toHaveText('2;1;');
async.done();
});
}));
@ -86,14 +86,14 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5];
rootTC.detectChanges();
.then((fixture) => {
fixture.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5];
fixture.detectChanges();
rootTC.debugElement.componentInstance.items = [6, 2, 7, 0, 4, 8];
rootTC.detectChanges();
fixture.debugElement.componentInstance.items = [6, 2, 7, 0, 4, 8];
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('6;2;7;0;4;8;');
expect(fixture.debugElement.nativeElement).toHaveText('6;2;7;0;4;8;');
async.done();
});
}));
@ -104,25 +104,26 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
.then((fixture) => {
// INIT
rootTC.debugElement.componentInstance.items = [{'name': 'misko'}, {'name': 'shyam'}];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('misko;shyam;');
fixture.debugElement.componentInstance.items =
[{'name': 'misko'}, {'name': 'shyam'}];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('misko;shyam;');
// GROW
(<any[]>rootTC.debugElement.componentInstance.items).push({'name': 'adam'});
rootTC.detectChanges();
(<any[]>fixture.debugElement.componentInstance.items).push({'name': 'adam'});
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('misko;shyam;adam;');
expect(fixture.debugElement.nativeElement).toHaveText('misko;shyam;adam;');
// SHRINK
ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 2);
ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 0);
rootTC.detectChanges();
ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 2);
ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 0);
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('shyam;');
expect(fixture.debugElement.nativeElement).toHaveText('shyam;');
async.done();
});
}));
@ -132,9 +133,9 @@ export function main() {
var template = '<ul><li template="ng-for #item of null">{{item}};</li></ul>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
}));
@ -143,17 +144,17 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('1;2;');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('1;2;');
rootTC.debugElement.componentInstance.items = null;
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('');
fixture.debugElement.componentInstance.items = null;
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
rootTC.debugElement.componentInstance.items = [1, 2, 3];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('1;2;3;');
fixture.debugElement.componentInstance.items = [1, 2, 3];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;');
async.done();
});
}));
@ -162,12 +163,12 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('1;2;');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('1;2;');
rootTC.debugElement.componentInstance.items = 'whaaa';
expect(() => rootTC.detectChanges()).toThrowError();
fixture.debugElement.componentInstance.items = 'whaaa';
expect(() => fixture.detectChanges()).toThrowError();
async.done();
});
}));
@ -176,11 +177,11 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent)
.then((rootTC) => {
.then((fixture) => {
var a = new Foo();
rootTC.debugElement.componentInstance.items = [a, a];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('foo;foo;');
fixture.debugElement.componentInstance.items = [a, a];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('foo;foo;');
async.done();
});
}));
@ -197,16 +198,16 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [['a', 'b'], ['c']];
rootTC.detectChanges();
rootTC.detectChanges();
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('a-2;b-2;|c-1;|');
.then((fixture) => {
fixture.debugElement.componentInstance.items = [['a', 'b'], ['c']];
fixture.detectChanges();
fixture.detectChanges();
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('a-2;b-2;|c-1;|');
rootTC.debugElement.componentInstance.items = [['e'], ['f', 'g']];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('e-1;|f-2;g-2;|');
fixture.debugElement.componentInstance.items = [['e'], ['f', 'g']];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('e-1;|f-2;g-2;|');
async.done();
});
@ -221,14 +222,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [['a', 'b'], ['c']];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('a-2;b-2;c-1;');
.then((fixture) => {
fixture.debugElement.componentInstance.items = [['a', 'b'], ['c']];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('a-2;b-2;c-1;');
rootTC.debugElement.componentInstance.items = [['e'], ['f', 'g']];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('e-1;f-2;g-2;');
fixture.debugElement.componentInstance.items = [['e'], ['f', 'g']];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('e-1;f-2;g-2;');
async.done();
});
}));
@ -240,14 +241,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('0123456789');
.then((fixture) => {
fixture.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('0123456789');
rootTC.debugElement.componentInstance.items = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('0123456789');
fixture.debugElement.componentInstance.items = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('0123456789');
async.done();
});
}));
@ -259,14 +260,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [0, 1, 2];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('falsefalsetrue');
.then((fixture) => {
fixture.debugElement.componentInstance.items = [0, 1, 2];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('falsefalsetrue');
rootTC.debugElement.componentInstance.items = [2, 1];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('falsetrue');
fixture.debugElement.componentInstance.items = [2, 1];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('falsetrue');
async.done();
});
}));
@ -278,14 +279,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [0, 1, 2];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('truefalsetrue');
.then((fixture) => {
fixture.debugElement.componentInstance.items = [0, 1, 2];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('truefalsetrue');
rootTC.debugElement.componentInstance.items = [2, 1];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('truefalse');
fixture.debugElement.componentInstance.items = [2, 1];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('truefalse');
async.done();
});
}));
@ -297,14 +298,14 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.items = [0, 1, 2, 3];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('falsetruefalsetrue');
.then((fixture) => {
fixture.debugElement.componentInstance.items = [0, 1, 2, 3];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('falsetruefalsetrue');
rootTC.debugElement.componentInstance.items = [2, 1];
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('falsetrue');
fixture.debugElement.componentInstance.items = [2, 1];
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('falsetrue');
async.done();
});
}));
@ -318,10 +319,10 @@ export function main() {
ComponentUsingTestComponent,
'<test-cmp><li template="#item #i=index">{{i}}: {{item}};</li></test-cmp>')
.createAsync(ComponentUsingTestComponent)
.then((rootTC) => {
var testComponent = rootTC.debugElement.componentViewChildren[0];
.then((fixture) => {
var testComponent = fixture.debugElement.componentViewChildren[0];
testComponent.componentInstance.items = ['a', 'b', 'c'];
rootTC.detectChanges();
fixture.detectChanges();
expect(testComponent.nativeElement).toHaveText('0: a;1: b;2: c;');
async.done();

View File

@ -26,11 +26,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
}));
@ -42,11 +42,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello2');
expect(fixture.debugElement.nativeElement).toHaveText('hello2');
async.done();
});
}));
@ -57,24 +57,24 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(fixture.debugElement.nativeElement).toHaveText('');
rootTC.debugElement.componentInstance.booleanCondition = true;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.booleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(fixture.debugElement.nativeElement).toHaveText('hello');
rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
@ -87,36 +87,36 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(fixture.debugElement.nativeElement).toHaveText('');
rootTC.debugElement.componentInstance.booleanCondition = true;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.booleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(fixture.debugElement.nativeElement).toHaveText('hello');
rootTC.debugElement.componentInstance.nestedBooleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.nestedBooleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(fixture.debugElement.nativeElement).toHaveText('');
rootTC.debugElement.componentInstance.nestedBooleanCondition = true;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.nestedBooleanCondition = true;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(fixture.debugElement.nativeElement).toHaveText('hello');
rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.booleanCondition = false;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
@ -133,25 +133,25 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(3);
expect(DOM.getText(rootTC.debugElement.nativeElement))
expect(DOM.getText(fixture.debugElement.nativeElement))
.toEqual('helloNumberhelloStringhelloFunction');
rootTC.debugElement.componentInstance.numberCondition = 0;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.numberCondition = 0;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('helloString');
expect(fixture.debugElement.nativeElement).toHaveText('helloString');
rootTC.debugElement.componentInstance.numberCondition = 1;
rootTC.debugElement.componentInstance.stringCondition = "bar";
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.numberCondition = 1;
fixture.debugElement.componentInstance.stringCondition = "bar";
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('helloNumber');
expect(fixture.debugElement.nativeElement).toHaveText('helloNumber');
async.done();
});
}));
@ -164,17 +164,17 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(fixture.debugElement.nativeElement).toHaveText('hello');
rootTC.debugElement.componentInstance.numberCondition = 2;
rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
@ -186,15 +186,16 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
DOM.addClass(DOM.querySelector(rootTC.debugElement.nativeElement, 'copy-me'),
.then((fixture) => {
fixture.detectChanges();
DOM.addClass(DOM.querySelector(fixture.debugElement.nativeElement, 'copy-me'),
"foo");
rootTC.debugElement.componentInstance.numberCondition = 2;
rootTC.detectChanges();
expect(DOM.hasClass(
DOM.querySelector(rootTC.debugElement.nativeElement, 'copy-me'), "foo"))
fixture.debugElement.componentInstance.numberCondition = 2;
fixture.detectChanges();
expect(
DOM.hasClass(DOM.querySelector(fixture.debugElement.nativeElement, 'copy-me'),
"foo"))
.toBe(true);
async.done();
@ -209,11 +210,11 @@ export function main() {
tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent)
.then((rootTC) => {
expect(() => rootTC.detectChanges()).toThrowError();
expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError();
expect(DOM.querySelectorAll(fixture.debugElement.nativeElement, 'copy-me').length)
.toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
}));

View File

@ -30,9 +30,9 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
.then((fixture) => {
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px');
@ -46,19 +46,19 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
.then((fixture) => {
var expr: Map<string, any>;
rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px');
expr = rootTC.debugElement.componentInstance.expr;
expr = fixture.debugElement.componentInstance.expr;
expr['max-width'] = '30%';
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('30%');
@ -72,16 +72,16 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
.then((fixture) => {
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px');
StringMapWrapper.delete(rootTC.debugElement.componentInstance.expr, 'max-width');
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width');
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('');
@ -95,22 +95,22 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
.then((fixture) => {
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px');
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px');
StringMapWrapper.delete(rootTC.debugElement.componentInstance.expr, 'max-width');
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width');
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('');
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px');
@ -124,23 +124,23 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
.then((fixture) => {
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px');
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px');
StringMapWrapper.delete(rootTC.debugElement.componentInstance.expr, 'max-width');
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width');
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px');
rootTC.detectChanges();
expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
fixture.detectChanges();
expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('');

View File

@ -29,17 +29,17 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when a');
fixture.debugElement.componentInstance.switchValue = 'a';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when a');
rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when b');
fixture.debugElement.componentInstance.switchValue = 'b';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when b');
async.done();
});
@ -55,17 +55,17 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when default');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when default');
rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when a');
fixture.debugElement.componentInstance.switchValue = 'a';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when a');
rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when default');
fixture.debugElement.componentInstance.switchValue = 'b';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when default');
async.done();
});
@ -85,18 +85,18 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement)
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement)
.toHaveText('when default1;when default2;');
rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when a1;when a2;');
fixture.debugElement.componentInstance.switchValue = 'a';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when a1;when a2;');
rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when b1;when b2;');
fixture.debugElement.componentInstance.switchValue = 'b';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when b1;when b2;');
async.done();
});
@ -115,28 +115,28 @@ export function main() {
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.debugElement.componentInstance.when1 = 'a';
rootTC.debugElement.componentInstance.when2 = 'b';
rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when 1;');
.then((fixture) => {
fixture.debugElement.componentInstance.when1 = 'a';
fixture.debugElement.componentInstance.when2 = 'b';
fixture.debugElement.componentInstance.switchValue = 'a';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when 1;');
rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when 2;');
fixture.debugElement.componentInstance.switchValue = 'b';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when 2;');
rootTC.debugElement.componentInstance.switchValue = 'c';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when default;');
fixture.debugElement.componentInstance.switchValue = 'c';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when default;');
rootTC.debugElement.componentInstance.when1 = 'c';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when 1;');
fixture.debugElement.componentInstance.when1 = 'c';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when 1;');
rootTC.debugElement.componentInstance.when1 = 'd';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('when default;');
fixture.debugElement.componentInstance.when1 = 'd';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('when default;');
async.done();
});

View File

@ -22,9 +22,9 @@ export function main() {
var template = '<div>{{text}}<span ng-non-bindable>{{text}}</span></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('foo{{text}}');
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('foo{{text}}');
async.done();
});
}));
@ -34,12 +34,12 @@ export function main() {
var template = '<div ng-non-bindable><span id=child test-dec>{{text}}</span></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
.then((fixture) => {
fixture.detectChanges();
// We must use DOM.querySelector instead of rootTC.query here
// We must use DOM.querySelector instead of fixture.query here
// since the elements inside are not compiled.
var span = DOM.querySelector(rootTC.debugElement.nativeElement, '#child');
var span = DOM.querySelector(fixture.debugElement.nativeElement, '#child');
expect(DOM.hasClass(span, 'compiled')).toBeFalsy();
async.done();
});
@ -50,9 +50,9 @@ export function main() {
var template = '<div><span id=child ng-non-bindable test-dec>{{text}}</span></div>';
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((rootTC) => {
rootTC.detectChanges();
var span = DOM.querySelector(rootTC.debugElement.nativeElement, '#child');
.then((fixture) => {
fixture.detectChanges();
var span = DOM.querySelector(fixture.debugElement.nativeElement, '#child');
expect(DOM.hasClass(span, 'compiled')).toBeTruthy();
async.done();
});

View File

@ -1,6 +1,6 @@
import {Component, Directive, View, Output, EventEmitter} from 'angular2/angular2';
import {
RootTestComponent,
ComponentFixture,
afterEach,
AsyncTestCompleter,
TestComponentBuilder,
@ -51,12 +51,12 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"login": new Control("loginValue")});
rootTC.detectChanges();
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("loginValue");
async.done();
});
@ -70,10 +70,10 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var input = fixture.debugElement.query(By.css("input"));
input.nativeElement.value = "updatedValue";
dispatchEvent(input.nativeElement, "change");
@ -90,22 +90,22 @@ export function main() {
<span>{{name}}</span>
</div>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.form = new ControlGroup({});
rootTC.debugElement.componentInstance.name = 'old';
fixture.debugElement.componentInstance.form = new ControlGroup({});
fixture.debugElement.componentInstance.name = 'old';
tick();
var form = rootTC.debugElement.query(By.css("form"));
var form = fixture.debugElement.query(By.css("form"));
dispatchEvent(form.nativeElement, "submit");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual('updated');
expect(fixture.debugElement.componentInstance.name).toEqual('updated');
})));
it("should work with single controls",
@ -114,11 +114,11 @@ export function main() {
var t = `<div><input type="text" [ng-form-control]="form"></div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = control;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = control;
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("loginValue");
input.nativeElement.value = "updatedValue";
@ -135,16 +135,16 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"login": new Control("oldValue")});
rootTC.detectChanges();
fixture.detectChanges();
rootTC.debugElement.componentInstance.form =
fixture.debugElement.componentInstance.form =
new ControlGroup({"login": new Control("newValue")});
rootTC.detectChanges();
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("newValue");
async.done();
});
@ -159,15 +159,15 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
login.updateValue("newValue");
rootTC.detectChanges();
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("newValue");
async.done();
});
@ -182,11 +182,11 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var loginEl = rootTC.debugElement.query(By.css("input"));
var loginEl = fixture.debugElement.query(By.css("input"));
expect(login.touched).toBe(false);
dispatchEvent(loginEl.nativeElement, "blur");
@ -204,18 +204,18 @@ export function main() {
<input type="text" ng-control="text">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"text": new Control("old")});
rootTC.detectChanges();
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("old");
input.nativeElement.value = "new";
dispatchEvent(input.nativeElement, "input");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"text": "new"});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"text": "new"});
async.done();
});
}));
@ -226,17 +226,17 @@ export function main() {
<input ng-control="text">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"text": new Control("old")});
rootTC.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
fixture.detectChanges();
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("old");
input.nativeElement.value = "new";
dispatchEvent(input.nativeElement, "input");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"text": "new"});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"text": "new"});
async.done();
});
}));
@ -247,18 +247,18 @@ export function main() {
<textarea ng-control="text"></textarea>
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"text": new Control('old')});
rootTC.detectChanges();
fixture.detectChanges();
var textarea = rootTC.debugElement.query(By.css("textarea"));
var textarea = fixture.debugElement.query(By.css("textarea"));
expect(textarea.nativeElement.value).toEqual("old");
textarea.nativeElement.value = "new";
dispatchEvent(textarea.nativeElement, "input");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"text": 'new'});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"text": 'new'});
async.done();
});
}));
@ -269,18 +269,18 @@ export function main() {
<input type="checkbox" ng-control="checkbox">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"checkbox": new Control(true)});
rootTC.detectChanges();
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.checked).toBe(true);
input.nativeElement.checked = false;
dispatchEvent(input.nativeElement, "change");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"checkbox": false});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"checkbox": false});
async.done();
});
}));
@ -291,18 +291,18 @@ export function main() {
<input type="number" ng-control="num">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"num": new Control(10)});
rootTC.detectChanges();
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("10");
input.nativeElement.value = "20";
dispatchEvent(input.nativeElement, "change");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"num": 20});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"num": 20});
async.done();
});
}));
@ -316,20 +316,20 @@ export function main() {
</select>
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"city": new Control("SF")});
rootTC.detectChanges();
fixture.detectChanges();
var select = rootTC.debugElement.query(By.css("select"));
var sfOption = rootTC.debugElement.query(By.css("option"));
var select = fixture.debugElement.query(By.css("select"));
var sfOption = fixture.debugElement.query(By.css("option"));
expect(select.nativeElement.value).toEqual('SF');
expect(sfOption.nativeElement.selected).toBe(true);
select.nativeElement.value = 'NYC';
dispatchEvent(select.nativeElement, "change");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"city": 'NYC'});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"city": 'NYC'});
expect(sfOption.nativeElement.selected).toBe(false);
async.done();
});
@ -343,17 +343,18 @@ export function main() {
</select>
</div>`;
var rootTC;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rtc) => rootTC = rtc);
var fixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(compFixture) => fixture = compFixture);
tick();
rootTC.debugElement.componentInstance.form =
fixture.debugElement.componentInstance.form =
new ControlGroup({"city": new Control("NYC")});
rootTC.debugElement.componentInstance.data = ['SF', 'NYC'];
rootTC.detectChanges();
fixture.debugElement.componentInstance.data = ['SF', 'NYC'];
fixture.detectChanges();
tick();
var select = rootTC.debugElement.query(By.css('select'));
var select = fixture.debugElement.query(By.css('select'));
expect(select.nativeElement.value).toEqual('NYC');
})));
@ -363,17 +364,17 @@ export function main() {
<input type="text" ng-control="name" wrapped-value>
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"name": new Control("aa")});
rootTC.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
fixture.detectChanges();
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("!aa!");
input.nativeElement.value = "!bb!";
dispatchEvent(input.nativeElement, "change");
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
async.done();
});
}));
@ -384,16 +385,16 @@ export function main() {
<my-input ng-control="name"></my-input>
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form =
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form =
new ControlGroup({"name": new Control("aa")});
rootTC.detectChanges();
var input = rootTC.debugElement.query(By.css("my-input"));
fixture.detectChanges();
var input = fixture.debugElement.query(By.css("my-input"));
expect(input.componentInstance.value).toEqual("!aa!");
input.componentInstance.value = "!bb!";
ObservableWrapper.subscribe(input.componentInstance.onChange, (value) => {
expect(rootTC.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
expect(fixture.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
async.done();
});
input.componentInstance.dispatchChangeEvent();
@ -414,13 +415,13 @@ export function main() {
<input type="text" ng-control="max" maxlength="3">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var required = rootTC.debugElement.query(By.css("[required]"));
var minLength = rootTC.debugElement.query(By.css("[minlength]"));
var maxLength = rootTC.debugElement.query(By.css("[maxlength]"));
var required = fixture.debugElement.query(By.css("[required]"));
var minLength = fixture.debugElement.query(By.css("[minlength]"));
var maxLength = fixture.debugElement.query(By.css("[maxlength]"));
required.nativeElement.value = "";
minLength.nativeElement.value = "1";
@ -485,12 +486,12 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
expect(form.valid).toEqual(true);
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
input.nativeElement.value = "";
dispatchEvent(input.nativeElement, "change");
@ -510,16 +511,17 @@ export function main() {
<input type="text" ng-control="login">
</div>`;
var rootTC;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => rootTC = root);
var fixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => fixture =
root);
tick();
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
expect(form.hasError("required", ["login"])).toEqual(true);
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
input.nativeElement.value = "wrong value";
dispatchEvent(input.nativeElement, "change");
@ -548,11 +550,11 @@ export function main() {
</div>
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
var input = fixture.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("value");
async.done();
});
@ -569,10 +571,10 @@ export function main() {
</div>
</div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
var input = rootTC.debugElement.query(By.css("input"));
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var input = fixture.debugElement.query(By.css("input"));
input.nativeElement.value = "updatedValue";
dispatchEvent(input.nativeElement, "change");
@ -591,47 +593,49 @@ export function main() {
var t =
`<div [ng-form-model]="form"><input type="text" ng-control="name" [(ng-model)]="name"></div>`;
var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; });
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = 'oldValue';
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = 'oldValue';
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue");
input.value = "updatedValue";
dispatchEvent(input, "change");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
})));
it("should support ng-model for single fields",
inject(
[TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var form = new Control("");
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var form = new Control("");
var t = `<div><input type="text" [ng-form-control]="form" [(ng-model)]="name"></div>`;
var t =
`<div><input type="text" [ng-form-control]="form" [(ng-model)]="name"></div>`;
var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; });
tick();
rootTC.debugElement.componentInstance.form = form;
rootTC.debugElement.componentInstance.name = "oldValue";
rootTC.detectChanges();
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { fixture = root; });
tick();
fixture.debugElement.componentInstance.form = form;
fixture.debugElement.componentInstance.name = "oldValue";
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue");
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue");
input.value = "updatedValue";
dispatchEvent(input, "change");
tick();
input.value = "updatedValue";
dispatchEvent(input, "change");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
})));
expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
})));
describe("template-driven forms", () => {
it("should add new controls and control groups",
@ -642,14 +646,14 @@ export function main() {
</div>
</form>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = null;
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = null;
fixture.detectChanges();
var form = rootTC.debugElement.componentViewChildren[0].inject(NgForm);
var form = fixture.debugElement.componentViewChildren[0].inject(NgForm);
expect(form.controls['user']).not.toBeDefined();
tick();
@ -662,17 +666,17 @@ export function main() {
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<div><form (ng-submit)="name='updated'"></form></div>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = 'old';
var form = rootTC.debugElement.query(By.css("form"));
fixture.debugElement.componentInstance.name = 'old';
var form = fixture.debugElement.query(By.css("form"));
dispatchEvent(form.nativeElement, "submit");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual("updated");
expect(fixture.debugElement.componentInstance.name).toEqual("updated");
})));
it("should not create a template-driven form when ng-no-form is used",
@ -680,11 +684,11 @@ export function main() {
var t = `<form ng-no-form>
</form>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.name = null;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.name = null;
fixture.detectChanges();
expect(rootTC.debugElement.componentViewChildren.length).toEqual(0);
expect(fixture.debugElement.componentViewChildren.length).toEqual(0);
async.done();
});
}));
@ -697,20 +701,20 @@ export function main() {
</div>
</form>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = 'show';
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = 'show';
fixture.detectChanges();
tick();
var form = rootTC.debugElement.componentViewChildren[0].inject(NgForm);
var form = fixture.debugElement.componentViewChildren[0].inject(NgForm);
expect(form.controls['login']).toBeDefined();
rootTC.debugElement.componentInstance.name = 'hide';
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = 'hide';
fixture.detectChanges();
tick();
expect(form.controls['login']).not.toBeDefined();
@ -725,19 +729,19 @@ export function main() {
</form>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = 'show';
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = 'show';
fixture.detectChanges();
tick();
var form = rootTC.debugElement.componentViewChildren[0].inject(NgForm);
var form = fixture.debugElement.componentViewChildren[0].inject(NgForm);
expect(form.controls['user']).toBeDefined();
rootTC.debugElement.componentInstance.name = 'hide';
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = 'hide';
fixture.detectChanges();
tick();
expect(form.controls['user']).not.toBeDefined();
@ -749,22 +753,22 @@ export function main() {
<input type="text" ng-control="name" [(ng-model)]="name">
</form>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = "oldValue";
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = "oldValue";
fixture.detectChanges();
tick();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue");
input.value = "updatedValue";
dispatchEvent(input, "change");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
})));
@ -772,21 +776,21 @@ export function main() {
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<div><input type="text" [(ng-model)]="name"></div>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = "oldValue";
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = "oldValue";
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue");
input.value = "updatedValue";
dispatchEvent(input, "change");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
})));
});
@ -798,21 +802,21 @@ export function main() {
var t = `<div><input type="text" [ng-form-control]="form"></div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(sortedClassList(input)).toEqual(['ng-invalid', 'ng-pristine', 'ng-untouched']);
dispatchEvent(input, "blur");
rootTC.detectChanges();
fixture.detectChanges();
expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-touched"]);
input.value = "updatedValue";
dispatchEvent(input, "change");
rootTC.detectChanges();
fixture.detectChanges();
expect(sortedClassList(input)).toEqual(["ng-dirty", "ng-touched", "ng-valid"]);
async.done();
@ -825,21 +829,21 @@ export function main() {
var t = `<form [ng-form-model]="form"><input type="text" ng-control="name"></form>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-untouched"]);
dispatchEvent(input, "blur");
rootTC.detectChanges();
fixture.detectChanges();
expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-touched"]);
input.value = "updatedValue";
dispatchEvent(input, "change");
rootTC.detectChanges();
fixture.detectChanges();
expect(sortedClassList(input)).toEqual(["ng-dirty", "ng-touched", "ng-valid"]);
async.done();
@ -850,21 +854,21 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var t = `<div><input [(ng-model)]="name" required></div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.debugElement.componentInstance.name = "";
rootTC.detectChanges();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
fixture.debugElement.componentInstance.name = "";
fixture.detectChanges();
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-untouched"]);
dispatchEvent(input, "blur");
rootTC.detectChanges();
fixture.detectChanges();
expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-touched"]);
input.value = "updatedValue";
dispatchEvent(input, "change");
rootTC.detectChanges();
fixture.detectChanges();
expect(sortedClassList(input)).toEqual(["ng-dirty", "ng-touched", "ng-valid"]);
async.done();
@ -879,27 +883,27 @@ export function main() {
var t =
`<div><input type="text" [ng-form-control]="form" [(ng-model)]="name"></div>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges();
fixture.debugElement.componentInstance.form = form;
fixture.detectChanges();
// In Firefox, effective text selection in the real DOM requires an actual focus
// of the field. This is not an issue in a new HTML document.
if (browserDetection.isFirefox) {
var fakeDoc = DOM.createHtmlDocument();
DOM.appendChild(fakeDoc.body, rootTC.debugElement.nativeElement);
DOM.appendChild(fakeDoc.body, fixture.debugElement.nativeElement);
}
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
input.value = "aa";
input.selectionStart = 1;
dispatchEvent(input, "change");
tick();
rootTC.detectChanges();
fixture.detectChanges();
// selection start has not changed because we did not reset the value
expect(input.selectionStart).toEqual(1);
@ -908,33 +912,33 @@ export function main() {
it("should update the view when the model is set back to what used to be in the view",
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<input type="text" [(ng-model)]="name">`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.debugElement.componentInstance.name = "";
rootTC.detectChanges();
fixture.debugElement.componentInstance.name = "";
fixture.detectChanges();
// Type "aa" into the input.
var input = rootTC.debugElement.query(By.css("input")).nativeElement;
var input = fixture.debugElement.query(By.css("input")).nativeElement;
input.value = "aa";
input.selectionStart = 1;
dispatchEvent(input, "change");
tick();
rootTC.detectChanges();
expect(rootTC.debugElement.componentInstance.name).toEqual("aa");
fixture.detectChanges();
expect(fixture.debugElement.componentInstance.name).toEqual("aa");
// Programatically update the input value to be "bb".
rootTC.debugElement.componentInstance.name = "bb";
fixture.debugElement.componentInstance.name = "bb";
tick();
rootTC.detectChanges();
fixture.detectChanges();
expect(input.value).toEqual("bb");
// Programatically set it back to "aa".
rootTC.debugElement.componentInstance.name = "aa";
fixture.debugElement.componentInstance.name = "aa";
tick();
rootTC.detectChanges();
fixture.detectChanges();
expect(input.value).toEqual("aa");
})));
it("should not crash when validity is checked from a binding",
@ -944,11 +948,11 @@ export function main() {
// fixed.
var t = `<form><div ng-control-group="x" #x="form">
<input type="text" ng-control="test"></div>{{x.valid}}</form>`;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
(root) => { fixture = root; });
tick();
rootTC.detectChanges();
fixture.detectChanges();
})));
});
});

View File

@ -13,7 +13,7 @@ import {
it,
xit,
TestComponentBuilder,
RootTestComponent
ComponentFixture
} from 'angular2/testing_internal';
import {OnDestroy} from 'angular2/lifecycle_hooks';
@ -24,7 +24,7 @@ import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component
import {ElementRef} from 'angular2/src/core/linker/element_ref';
import {DOCUMENT} from 'angular2/src/core/render/render';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {RootTestComponent_} from "angular2/src/testing/test_component_builder";
import {ComponentFixture_} from "angular2/src/testing/test_component_builder";
export function main() {
describe('DynamicComponentLoader', function() {
@ -232,7 +232,7 @@ export function main() {
DOM.appendChild(doc.body, rootEl);
loader.loadAsRoot(ChildComp, null, injector)
.then((componentRef) => {
var el = new RootTestComponent_(componentRef);
var el = new ComponentFixture_(componentRef);
expect(rootEl.parentNode).toBe(doc.body);
el.detectChanges();

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ import {
containsRegexp,
stringifyElement,
TestComponentBuilder,
RootTestComponent,
ComponentFixture,
fakeAsync,
tick
} from 'angular2/testing_internal';
@ -293,7 +293,7 @@ export function main() {
{template: '<simple string-prop="text"></simple>', directives: [Simple]}))
.overrideTemplate(Simple, '<ng-content></ng-content><p>P,</p>{{stringProp}}')
.createAsync(MainComp)
.then((main: RootTestComponent) => {
.then((main: ComponentFixture) => {
main.detectChanges();
@ -314,7 +314,7 @@ export function main() {
{template: '<simple string-prop="text"></simple>', directives: [Simple]}))
.overrideTemplate(Simple, '<style></style><p>P,</p>{{stringProp}}')
.createAsync(MainComp)
.then((main: RootTestComponent) => {
.then((main: ComponentFixture) => {
main.detectChanges();
expect(main.debugElement.nativeElement).toHaveText('P,text');

View File

@ -211,10 +211,10 @@ export function main() {
tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp)
.then((rtc) => {
rtc.debugElement.componentInstance.shouldShow = true;
rtc.detectChanges();
rtc.destroy();
.then((fixture) => {
fixture.debugElement.componentInstance.shouldShow = true;
fixture.detectChanges();
fixture.destroy();
async.done();
});

View File

@ -55,15 +55,15 @@ export function main() {
describe('integration', () => {
it('should work with mutable objects',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(TestComp).then((rootTC) => {
tcb.createAsync(TestComp).then((fixture) => {
let mutable: number[] = [1];
rootTC.debugElement.componentInstance.data = mutable;
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText("[\n 1\n]");
fixture.debugElement.componentInstance.data = mutable;
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText("[\n 1\n]");
mutable.push(2);
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText("[\n 1,\n 2\n]");
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText("[\n 1,\n 2\n]");
async.done();
});

View File

@ -91,15 +91,15 @@ export function main() {
describe('integration', () => {
it('should work with mutable arrays',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(TestComp).then((rootTC) => {
tcb.createAsync(TestComp).then((fixture) => {
let mutable: number[] = [1, 2];
rootTC.debugElement.componentInstance.data = mutable;
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('2');
fixture.debugElement.componentInstance.data = mutable;
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('2');
mutable.push(3);
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('2,3');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('2,3');
async.done();
});

View File

@ -1,5 +1,5 @@
import {
RootTestComponent,
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
@ -58,7 +58,7 @@ export function main() {
describe('Router lifecycle hooks', () => {
var tcb: TestComponentBuilder;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
var rtr;
beforeEachBindings(() => [
@ -87,7 +87,7 @@ export function main() {
directives: [RouterOutlet, RouterLink]
}))
.createAsync(MyComp)
.then((tc) => { rootTC = tc; });
.then((tc) => { fixture = tc; });
}
it('should call the onActivate hook', inject([AsyncTestCompleter], (async) => {
@ -95,8 +95,8 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigateByUrl('/on-activate'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('activate cmp');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('activate cmp');
expect(log).toEqual(['activate: null -> /on-activate']);
async.done();
});
@ -114,8 +114,8 @@ export function main() {
});
rtr.navigateByUrl('/parent-activate/child-activate')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('parent {activate cmp}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('parent {activate cmp}');
expect(log).toEqual([
'parent activate: null -> /parent-activate',
'activate: null -> /child-activate'
@ -131,8 +131,8 @@ export function main() {
.then((_) => rtr.navigateByUrl('/on-deactivate'))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('A');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual(['deactivate: /on-deactivate -> /a']);
async.done();
});
@ -147,13 +147,13 @@ export function main() {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('deactivate')) {
completer.resolve(true);
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('parent {deactivate cmp}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('parent {deactivate cmp}');
}
});
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('A');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual([
'deactivate: /child-deactivate -> null',
'parent deactivate: /parent-deactivate -> /a'
@ -169,16 +169,16 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigateByUrl('/on-reuse/1/a'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(log).toEqual([]);
expect(rootTC.debugElement.nativeElement).toHaveText('reuse {A}');
expect(fixture.debugElement.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1);
})
.then((_) => rtr.navigateByUrl('/on-reuse/2/b'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(log).toEqual(['reuse: /on-reuse/1 -> /on-reuse/2']);
expect(rootTC.debugElement.nativeElement).toHaveText('reuse {B}');
expect(fixture.debugElement.nativeElement).toHaveText('reuse {B}');
expect(cmpInstanceCount).toBe(1);
async.done();
});
@ -191,16 +191,16 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigateByUrl('/never-reuse/1/a'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(log).toEqual([]);
expect(rootTC.debugElement.nativeElement).toHaveText('reuse {A}');
expect(fixture.debugElement.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1);
})
.then((_) => rtr.navigateByUrl('/never-reuse/2/b'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(log).toEqual([]);
expect(rootTC.debugElement.nativeElement).toHaveText('reuse {B}');
expect(fixture.debugElement.nativeElement).toHaveText('reuse {B}');
expect(cmpInstanceCount).toBe(2);
async.done();
});
@ -218,8 +218,8 @@ export function main() {
});
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('canActivate {A}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('canActivate {A}');
expect(log).toEqual(['canActivate: null -> /can-activate']);
async.done();
});
@ -238,8 +238,8 @@ export function main() {
});
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
expect(log).toEqual(['canActivate: null -> /can-activate']);
async.done();
});
@ -252,8 +252,8 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('canDeactivate {A}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual([]);
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
@ -263,8 +263,8 @@ export function main() {
});
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('A');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
async.done();
});
@ -277,8 +277,8 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('canDeactivate {A}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual([]);
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
@ -288,8 +288,8 @@ export function main() {
});
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('canDeactivate {A}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
async.done();
});

View File

@ -1,5 +1,5 @@
import {
RootTestComponent,
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
@ -41,7 +41,7 @@ export function main() {
describe('navigation', () => {
var tcb: TestComponentBuilder;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
var rtr;
beforeEachBindings(() => [
@ -70,7 +70,7 @@ export function main() {
directives: [RouterOutlet, RouterLink]
}))
.createAsync(MyComp)
.then((tc) => { rootTC = tc; });
.then((tc) => { fixture = tc; });
}
it('should work in a simple case', inject([AsyncTestCompleter], (async) => {
@ -78,8 +78,8 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/test', component: HelloCmp})]))
.then((_) => rtr.navigateByUrl('/test'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('hello');
async.done();
});
}));
@ -91,13 +91,13 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/user/:name', component: UserCmp})]))
.then((_) => rtr.navigateByUrl('/user/brian'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('hello brian');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('hello brian');
})
.then((_) => rtr.navigateByUrl('/user/igor'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('hello igor');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('hello igor');
async.done();
});
}));
@ -108,8 +108,8 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/a/...', component: ParentCmp})]))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
async.done();
});
}));
@ -120,8 +120,8 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/a/...', component: ParentCmp})]))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
async.done();
});
}));
@ -132,8 +132,8 @@ export function main() {
.then((_) => rtr.config([new AsyncRoute({path: '/a/...', loader: parentLoader})]))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
async.done();
});
}));
@ -148,8 +148,8 @@ export function main() {
]))
.then((_) => rtr.navigateByUrl('/original'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('hello');
expect(location.urlChanges).toEqual(['/redirected']);
async.done();
});
@ -161,15 +161,15 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/team/:id/...', component: TeamCmp})]))
.then((_) => rtr.navigateByUrl('/team/angular/user/rado'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(rootTC.debugElement.nativeElement).toHaveText('team angular { hello rado }');
expect(fixture.debugElement.nativeElement).toHaveText('team angular { hello rado }');
})
.then((_) => rtr.navigateByUrl('/team/angular/user/victor'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(rootTC.debugElement.nativeElement)
expect(fixture.debugElement.nativeElement)
.toHaveText('team angular { hello victor }');
async.done();
});
@ -181,17 +181,17 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/team/:id/...', component: TeamCmp})]))
.then((_) => rtr.navigateByUrl('/team/angular/user/rado'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(childCmpInstanceCount).toBe(1);
expect(rootTC.debugElement.nativeElement).toHaveText('team angular { hello rado }');
expect(fixture.debugElement.nativeElement).toHaveText('team angular { hello rado }');
})
.then((_) => rtr.navigateByUrl('/team/dart/user/rado'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(cmpInstanceCount).toBe(2);
expect(childCmpInstanceCount).toBe(2);
expect(rootTC.debugElement.nativeElement).toHaveText('team dart { hello rado }');
expect(fixture.debugElement.nativeElement).toHaveText('team dart { hello rado }');
async.done();
});
}));
@ -203,8 +203,8 @@ export function main() {
]))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('true');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('true');
async.done();
});
}));
@ -218,8 +218,8 @@ export function main() {
]))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('true');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('true');
async.done();
});
}));
@ -231,8 +231,8 @@ export function main() {
[new Route({path: '/route-data-default', component: RouteDataCmp})]))
.then((_) => rtr.navigateByUrl('/route-data-default'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('');
async.done();
});
}));
@ -243,8 +243,9 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: AuxCmp})]))
.then((_) => rtr.navigateByUrl('/hello(modal)'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('main {hello} | aux {modal}');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement)
.toHaveText('main {hello} | aux {modal}');
async.done();
});
}));

View File

@ -79,10 +79,10 @@ export function main() {
it('should rethrow exceptions from component constructors',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(AppCmp).then((rootTC) => {
var router = rootTC.debugElement.componentInstance.router;
tcb.createAsync(AppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => {
expect(rootTC.debugElement.nativeElement).toHaveText('outer { oh no }');
expect(fixture.debugElement.nativeElement).toHaveText('outer { oh no }');
expect(error).toContainError('oops!');
async.done();
});
@ -98,8 +98,8 @@ export function main() {
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp)
.then((rootTC) => {
var router = rootTC.debugElement.componentInstance.router;
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
var position = 0;
var flipped = false;
var history =
@ -110,8 +110,8 @@ export function main() {
]
router.subscribe((_) => {
var location = rootTC.debugElement.componentInstance.location;
var element = rootTC.debugElement.nativeElement;
var location = fixture.debugElement.componentInstance.location;
var element = fixture.debugElement.nativeElement;
var path = location.path();
var entry = history[position];
@ -150,12 +150,12 @@ export function main() {
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp)
.then((rootTC) => {
var router = rootTC.debugElement.componentInstance.router;
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(rootTC.debugElement.nativeElement)
expect(fixture.debugElement.nativeElement)
.toHaveText('root { parent { hello } }');
expect(rootTC.debugElement.componentInstance.location.path())
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/parent/child');
async.done();
});
@ -171,12 +171,12 @@ export function main() {
(async, tcb: TestComponentBuilder) => {
tcb.createAsync(HierarchyAppCmp)
.then((rootTC) => {
var router = rootTC.debugElement.componentInstance.router;
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
expect(rootTC.debugElement.nativeElement)
expect(fixture.debugElement.nativeElement)
.toHaveText('root { parent { hello } }');
expect(rootTC.debugElement.componentInstance.location.path())
expect(fixture.debugElement.componentInstance.location.path())
.toEqual('/my/app/parent/child');
async.done();
});
@ -194,12 +194,12 @@ export function main() {
it('should recognize and return querystring params with the injected RouteParams',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(QueryStringAppCmp)
.then((rootTC) => {
var router = rootTC.debugElement.componentInstance.router;
.then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
router.subscribe((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(rootTC.debugElement.nativeElement)
expect(fixture.debugElement.nativeElement)
.toHaveText('qParam = search-for-something');
/*
expect(applicationRef.hostComponent.location.path())
@ -207,7 +207,7 @@ export function main() {
async.done();
});
router.navigateByUrl('/qs?q=search-for-something');
rootTC.detectChanges();
fixture.detectChanges();
});
}));
});

View File

@ -1,5 +1,5 @@
import {
RootTestComponent,
ComponentFixture,
AsyncTestCompleter,
beforeEach,
ddescribe,
@ -43,7 +43,7 @@ import {DOM} from 'angular2/src/core/dom/dom_adapter';
export function main() {
describe('router-link directive', function() {
var tcb: TestComponentBuilder;
var rootTC: RootTestComponent;
var fixture: ComponentFixture;
var router, location;
beforeEachBindings(() => [
@ -70,7 +70,7 @@ export function main() {
directives: [RouterOutlet, RouterLink]
}))
.createAsync(MyComp)
.then((tc) => { rootTC = tc; });
.then((tc) => { fixture = tc; });
}
it('should generate absolute hrefs that include the base href',
@ -81,8 +81,8 @@ export function main() {
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(getHref(rootTC)).toEqual('/my/base/user');
fixture.detectChanges();
expect(getHref(fixture)).toEqual('/my/base/user');
async.done();
});
}));
@ -94,8 +94,8 @@ export function main() {
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(getHref(rootTC)).toEqual('/user');
fixture.detectChanges();
expect(getHref(fixture)).toEqual('/user');
async.done();
});
}));
@ -107,10 +107,10 @@ export function main() {
[new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.debugElement.componentInstance.name = 'brian';
rootTC.detectChanges();
expect(rootTC.debugElement.nativeElement).toHaveText('brian');
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
fixture.debugElement.componentInstance.name = 'brian';
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('brian');
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[0].nativeElement,
'href'))
.toEqual('/user/brian');
async.done();
@ -125,8 +125,8 @@ export function main() {
[new Route({path: '/page/:number', component: SiblingPageCmp, name: 'Page'})]))
.then((_) => router.navigateByUrl('/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
fixture.detectChanges();
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
.componentViewChildren[0]
.nativeElement,
'href'))
@ -144,8 +144,8 @@ export function main() {
]))
.then((_) => router.navigateByUrl('/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
fixture.detectChanges();
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
.componentViewChildren[0]
.nativeElement,
'href'))
@ -162,8 +162,8 @@ export function main() {
]))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
fixture.detectChanges();
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
.componentViewChildren[0]
.nativeElement,
'href'))
@ -181,7 +181,7 @@ export function main() {
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
var link = ListWrapper.toJSON(['Book', {number: 100}]);
expect(() => rootTC.detectChanges())
expect(() => fixture.detectChanges())
.toThrowErrorWith(
`Link "${link}" is ambiguous, use "./" or "../" to disambiguate.`);
async.done();
@ -200,8 +200,8 @@ export function main() {
]))
.then((_) => router.navigate(['/ChildWithGrandchild']))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
fixture.detectChanges();
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
.componentViewChildren[0]
.nativeElement,
'href'))
@ -217,14 +217,14 @@ export function main() {
[new Route({path: '/book/:title/...', component: BookCmp, name: 'Book'})]))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
fixture.detectChanges();
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
.componentViewChildren[0]
.nativeElement,
'href'))
.toEqual('/book/1984/page/100');
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
expect(DOM.getAttribute(fixture.debugElement.componentViewChildren[1]
.componentViewChildren[2]
.componentViewChildren[0]
.nativeElement,
@ -245,9 +245,9 @@ export function main() {
<a [router-link]="['./BetterChild']" class="better-child-link">Better Child</a>
<router-outlet></router-outlet>`))
.then((_) => {
var element = rootTC.debugElement.nativeElement;
var element = fixture.debugElement.nativeElement;
rootTC.detectChanges();
fixture.detectChanges();
var link1 = DOM.querySelector(element, '.child-link');
var link2 = DOM.querySelector(element, '.better-child-link');
@ -256,7 +256,7 @@ export function main() {
expect(link2).not.toHaveCssClass('router-link-active');
router.subscribe((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(link1).not.toHaveCssClass('router-link-active');
expect(link2).toHaveCssClass('router-link-active');
@ -280,9 +280,9 @@ export function main() {
<a [router-link]="['./ChildWithGrandchild/Grandchild']" class="child-with-grandchild-link">Better Child</a>
<router-outlet></router-outlet>`))
.then((_) => {
var element = rootTC.debugElement.nativeElement;
var element = fixture.debugElement.nativeElement;
rootTC.detectChanges();
fixture.detectChanges();
var link1 = DOM.querySelector(element, '.child-link');
var link2 = DOM.querySelector(element, '.child-with-grandchild-link');
@ -291,7 +291,7 @@ export function main() {
expect(link2).not.toHaveCssClass('router-link-active');
router.subscribe((_) => {
rootTC.detectChanges();
fixture.detectChanges();
expect(link1).not.toHaveCssClass('router-link-active');
expect(link2).toHaveCssClass('router-link-active');
@ -312,7 +312,7 @@ export function main() {
describe('when clicked', () => {
var clickOnElement = function(view) {
var anchorEl = rootTC.debugElement.componentViewChildren[0].nativeElement;
var anchorEl = fixture.debugElement.componentViewChildren[0].nativeElement;
var dispatchedEvent = DOM.createMouseEvent('click');
DOM.dispatchEvent(anchorEl, dispatchedEvent);
return dispatchedEvent;
@ -324,9 +324,9 @@ export function main() {
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
var dispatchedEvent = clickOnElement(rootTC);
var dispatchedEvent = clickOnElement(fixture);
expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
// router navigation is async.
@ -345,9 +345,9 @@ export function main() {
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
fixture.detectChanges();
var dispatchedEvent = clickOnElement(rootTC);
var dispatchedEvent = clickOnElement(fixture);
expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
// router navigation is async.
@ -361,7 +361,7 @@ export function main() {
});
}
function getHref(tc: RootTestComponent) {
function getHref(tc: ComponentFixture) {
return DOM.getAttribute(tc.debugElement.componentViewChildren[0].nativeElement, 'href');
}

View File

@ -95,10 +95,10 @@ export function main() {
it('should instantiate a component with valid DOM',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ChildComp).then((rootTestComponent) => {
rootTestComponent.detectChanges();
tcb.createAsync(ChildComp).then((componentFixture) => {
componentFixture.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Original Child');
expect(componentFixture.debugElement.nativeElement).toHaveText('Original Child');
async.done();
});
}));
@ -106,13 +106,13 @@ export function main() {
it('should allow changing members of the component',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(MyIfComp).then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('MyIf()');
tcb.createAsync(MyIfComp).then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf()');
rootTestComponent.debugElement.componentInstance.showMore = true;
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('MyIf(More)');
componentFixture.debugElement.componentInstance.showMore = true;
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf(More)');
async.done();
});
@ -123,9 +123,9 @@ export function main() {
tcb.overrideTemplate(MockChildComp, '<span>Mock</span>')
.createAsync(MockChildComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Mock');
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('Mock');
async.done();
});
@ -137,9 +137,9 @@ export function main() {
tcb.overrideView(ChildComp,
new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
.createAsync(ChildComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Modified Child');
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('Modified Child');
async.done();
});
@ -150,9 +150,9 @@ export function main() {
tcb.overrideDirective(ParentComp, ChildComp, MockChildComp)
.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Parent(Mock)');
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('Parent(Mock)');
async.done();
});
@ -165,9 +165,9 @@ export function main() {
tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp)
.overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp)
.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('Parent(Original Child(ChildChild Mock))');
async.done();
@ -180,9 +180,9 @@ export function main() {
tcb.overrideProviders(TestBindingsComp,
[provide(FancyService, {useClass: MockFancyService})])
.createAsync(TestBindingsComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('injected value: mocked out value');
async.done();
});
@ -195,9 +195,9 @@ export function main() {
tcb.overrideViewProviders(TestViewBindingsComp,
[provide(FancyService, {useClass: MockFancyService})])
.createAsync(TestViewBindingsComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('injected value: mocked out value');
async.done();
});

View File

@ -243,23 +243,23 @@ export function main() {
it('should instantiate a component with valid DOM',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(ChildComp).then((rootTestComponent) => {
rootTestComponent.detectChanges();
return tcb.createAsync(ChildComp).then((componentFixture) => {
componentFixture.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Original Child');
expect(componentFixture.debugElement.nativeElement).toHaveText('Original Child');
});
}));
it('should allow changing members of the component',
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(MyIfComp).then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('MyIf()');
return tcb.createAsync(MyIfComp).then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf()');
rootTestComponent.debugElement.componentInstance.showMore = true;
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('MyIf(More)');
componentFixture.debugElement.componentInstance.showMore = true;
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf(More)');
});
}));
@ -268,9 +268,9 @@ export function main() {
return tcb.overrideTemplate(MockChildComp, '<span>Mock</span>')
.createAsync(MockChildComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Mock');
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('Mock');
});
}));
@ -282,9 +282,9 @@ export function main() {
ChildComp,
new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
.createAsync(ChildComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Modified Child');
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('Modified Child');
});
}));
@ -294,9 +294,9 @@ export function main() {
return tcb.overrideDirective(ParentComp, ChildComp, MockChildComp)
.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement).toHaveText('Parent(Mock)');
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement).toHaveText('Parent(Mock)');
});
}));
@ -308,9 +308,9 @@ export function main() {
return tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp)
.overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp)
.createAsync(ParentComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('Parent(Original Child(ChildChild Mock))');
});
@ -322,9 +322,9 @@ export function main() {
return tcb.overrideProviders(TestProvidersComp,
[bind(FancyService).toClass(MockFancyService)])
.createAsync(TestProvidersComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('injected value: mocked out value');
});
}));
@ -336,9 +336,9 @@ export function main() {
return tcb.overrideViewProviders(TestViewProvidersComp,
[bind(FancyService).toClass(MockFancyService)])
.createAsync(TestViewProvidersComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
expect(rootTestComponent.debugElement.nativeElement)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('injected value: mocked out value');
});
}));

View File

@ -138,12 +138,12 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{ctxProp}}</div>'}))
.createAsync(MyComp)
.then((rootTC) => {
var renderEl = getRenderElement(rootTC.debugElement.elementRef);
.then((fixture) => {
var renderEl = getRenderElement(fixture.debugElement.elementRef);
expect(renderEl).toHaveText('');
rootTC.debugElement.componentInstance.ctxProp = 'Hello World!';
rootTC.detectChanges();
fixture.debugElement.componentInstance.ctxProp = 'Hello World!';
fixture.detectChanges();
expect(renderEl).toHaveText('Hello World!');
async.done();
@ -156,7 +156,7 @@ export function main() {
tcb.overrideView(MyComp, new ViewMetadata(
{template: '<input [title]="y" style="position:absolute">'}))
.createAsync(MyComp)
.then((rootTC) => {
.then((fixture) => {
var checkSetters = (elr) => {
var el = getRenderElement(elr);
renderer.setElementProperty(elr, 'tabIndex', 1);
@ -177,9 +177,9 @@ export function main() {
};
// root element
checkSetters(rootTC.debugElement.elementRef);
checkSetters(fixture.debugElement.elementRef);
// nested elements
checkSetters(rootTC.debugElement.componentViewChildren[0].elementRef);
checkSetters(fixture.debugElement.componentViewChildren[0].elementRef);
async.done();
});
@ -192,17 +192,17 @@ export function main() {
directives: [NgIf]
}))
.createAsync(MyComp)
.then((rootTC) => {
.then((fixture) => {
var rootEl = getRenderElement(rootTC.debugElement.elementRef);
var rootEl = getRenderElement(fixture.debugElement.elementRef);
expect(rootEl).toHaveText('');
rootTC.debugElement.componentInstance.ctxBoolProp = true;
rootTC.detectChanges();
fixture.debugElement.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
expect(rootEl).toHaveText('hello');
rootTC.debugElement.componentInstance.ctxBoolProp = false;
rootTC.detectChanges();
fixture.debugElement.componentInstance.ctxBoolProp = false;
fixture.detectChanges();
expect(rootEl).toHaveText('');
async.done();
@ -216,8 +216,8 @@ export function main() {
tcb.overrideView(MyComp,
new ViewMetadata({template: '<input [title]="y"></input>'}))
.createAsync(MyComp)
.then((rootTC) => {
var elRef = rootTC.debugElement.componentViewChildren[0].elementRef;
.then((fixture) => {
var elRef = fixture.debugElement.componentViewChildren[0].elementRef;
renderer.invokeElementMethod(elRef, 'setAttribute', ['a', 'b']);
expect(DOM.getAttribute(getRenderElement(elRef), 'a')).toEqual('b');

View File

@ -7,6 +7,6 @@
*
*/
export * from './src/testing/testing';
export {RootTestComponent, TestComponentBuilder} from './src/testing/test_component_builder';
export {ComponentFixture, TestComponentBuilder} from './src/testing/test_component_builder';
export * from './src/testing/test_injector';
export * from './src/testing/fake_async';

View File

@ -36,10 +36,9 @@ export function main() {
describe('button[md-button]', () => {
it('should handle a click on the button', inject([AsyncTestCompleter], (async) => {
builder.createAsync(TestApp).then(rootTestComponent => {
let testComponent = rootTestComponent.debugElement.componentInstance;
let buttonDebugElement =
getChildDebugElement(rootTestComponent.debugElement, 'button');
builder.createAsync(TestApp).then(fixture => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = getChildDebugElement(fixture.debugElement, 'button');
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
@ -49,10 +48,9 @@ export function main() {
}), 1000);
it('should disable the button', inject([AsyncTestCompleter], (async) => {
builder.createAsync(TestApp).then(rootTestComponent => {
let testAppComponent = rootTestComponent.debugElement.componentInstance;
let buttonDebugElement =
getChildDebugElement(rootTestComponent.debugElement, 'button');
builder.createAsync(TestApp).then(fixture => {
let testAppComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = getChildDebugElement(fixture.debugElement, 'button');
let buttonElement = buttonDebugElement.nativeElement;
// The button should initially be enabled.
@ -60,7 +58,7 @@ export function main() {
// After the disabled binding has been changed.
testAppComponent.isDisabled = true;
rootTestComponent.detectChanges();
fixture.detectChanges();
// The button should should now be disabled.
expect(buttonElement.disabled).toBe(true);
@ -82,9 +80,9 @@ export function main() {
});
it('should remove disabled anchors from tab order', inject([AsyncTestCompleter], (async) => {
builder.createAsync(TestApp).then(rootTestComponent => {
let testAppComponent = rootTestComponent.debugElement.componentInstance;
let anchorDebugElement = getChildDebugElement(rootTestComponent.debugElement, 'a');
builder.createAsync(TestApp).then(fixture => {
let testAppComponent = fixture.debugElement.componentInstance;
let anchorDebugElement = getChildDebugElement(fixture.debugElement, 'a');
let anchorElement = anchorDebugElement.nativeElement;
// The anchor should initially be in the tab order.
@ -92,7 +90,7 @@ export function main() {
// After the disabled binding has been changed.
testAppComponent.isDisabled = true;
rootTestComponent.detectChanges();
fixture.detectChanges();
// The anchor should now be out of the tab order.
expect(anchorElement.tabIndex).toBe(-1);