fix(Typings): Remove public exports added in 1926335b85

Closes #4147
This commit is contained in:
Jason Teplitz 2015-09-11 13:45:31 -07:00 committed by Misko Hevery
parent 0246b2a2cb
commit 787d1f955f
51 changed files with 943 additions and 868 deletions

View File

@ -60,27 +60,21 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
{ {
id: 'angular2/router', id: 'angular2/router',
references: ['./angular2.d.ts'], references: ['./angular2.d.ts'],
remapTypes: {Type: 'ng.Type'}, remapTypes: {Type: 'ng.Type', InjectableReference: 'ng.InjectableReference'},
modules: {'angular2/router': {namespace: 'ngRouter', id: 'angular2/router'}} modules: {'angular2/router': {namespace: 'ngRouter', id: 'angular2/router'}}
}, },
{ {
id: 'angular2/http', id: 'angular2/http',
references: ['./angular2.d.ts'], references: ['./angular2.d.ts'],
remapTypes: {Type: 'ng.Type', Observable: 'ng.Observable', EventEmitter: 'ng.EventEmitter'}, remapTypes: {Type: 'ng.Type', Observable: 'ng.Observable', EventEmitter: 'ng.EventEmitter', InjectableReference: 'ng.InjectableReference' },
modules: {'angular2/http': {namespace: 'ngHttp', id: 'angular2/http'}} modules: {'angular2/http': {namespace: 'ngHttp', id: 'angular2/http'}}
}, },
{ {
id: 'angular2/test_lib', id: 'angular2/test_lib',
references: ['./angular2.d.ts', '../jasmine/jasmine.d.ts'], references: ['./angular2.d.ts', '../jasmine/jasmine.d.ts'],
remapTypes: { remapTypes: { Type: 'ng.Type', Binding: 'ng.Binding', ViewMetadata: 'ng.ViewMetadata', Injector: 'ng.Injector',
Type: 'ng.Type', Predicate: 'ng.Predicate', ElementRef: 'ng.ElementRef', DebugElement: 'ng.DebugElement',
Binding: 'ng.Binding', InjectableReference: 'ng.InjectableReference' },
ViewMetadata: 'ng.ViewMetadata',
Injector: 'ng.Injector',
Predicate: 'ng.Predicate',
ElementRef: 'ng.ElementRef',
DebugElement: 'ng.DebugElement'
},
modules: {'angular2/test_lib': {namespace: 'ngTestLib', id: 'angular2/test_lib'}} modules: {'angular2/test_lib': {namespace: 'ngTestLib', id: 'angular2/test_lib'}}
} }
]; ];

View File

@ -1,4 +1,4 @@
export * from './core'; export * from './core';
export * from './profile'; export * from './profile';
export * from './lifecycle_hooks'; export * from './lifecycle_hooks';
export * from './bootstrap'; export * from './bootstrap';

View File

@ -19,8 +19,3 @@ export * from './src/core/directives';
export * from './src/core/forms'; export * from './src/core/forms';
export * from './src/core/debug'; export * from './src/core/debug';
export * from './src/core/change_detection'; export * from './src/core/change_detection';
export {Reflector, ReflectionInfo} from './src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from './src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from './src/core/reflection/types';

View File

@ -30,7 +30,6 @@ export {BaseRequestOptions, RequestOptions} from './src/http/base_request_option
export {BaseResponseOptions, ResponseOptions} from './src/http/base_response_options'; export {BaseResponseOptions, ResponseOptions} from './src/http/base_response_options';
export {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend'; export {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend';
export {JSONPBackend, JSONPConnection} from './src/http/backends/jsonp_backend'; export {JSONPBackend, JSONPConnection} from './src/http/backends/jsonp_backend';
export {BrowserJsonp} from './src/http/backends/browser_jsonp';
export {Http, Jsonp} from './src/http/http'; export {Http, Jsonp} from './src/http/http';
export {Headers} from './src/http/headers'; export {Headers} from './src/http/headers';

View File

@ -7,47 +7,12 @@
export {Router, RootRouter} from './src/router/router'; export {Router, RootRouter} from './src/router/router';
export {RouterOutlet} from './src/router/router_outlet'; export {RouterOutlet} from './src/router/router_outlet';
export {
DynamicComponentLoader,
ComponentRef,
ElementRef,
Compiler,
AppViewManager,
ViewRef,
HostViewRef,
ProtoViewRef,
ViewContainerRef,
TemplateRef
} from './core';
export {
Renderer,
RenderElementRef,
RenderViewRef,
RenderProtoViewRef,
RenderEventDispatcher,
RenderFragmentRef,
RenderViewWithFragments
} from './render';
export {
Binding,
Injector,
ResolvedBinding,
Key,
Dependency,
ProtoInjector,
DependencyProvider,
BindingWithVisibility,
Visibility,
ResolvedFactory
} from './src/core/di';
export {RouterLink} from './src/router/router_link'; export {RouterLink} from './src/router/router_link';
export {RouteParams} from './src/router/instruction'; export {RouteParams} from './src/router/instruction';
export {RouteRegistry} from './src/router/route_registry'; export {RouteRegistry} from './src/router/route_registry';
export {LocationStrategy} from './src/router/location_strategy'; export {LocationStrategy} from './src/router/location_strategy';
export {HashLocationStrategy} from './src/router/hash_location_strategy'; export {HashLocationStrategy} from './src/router/hash_location_strategy';
export {PathLocationStrategy} from './src/router/path_location_strategy'; export {PathLocationStrategy} from './src/router/path_location_strategy';
export {PathRecognizer, PathMatch} from './src/router/path_recognizer';
export {RouteHandler} from './src/router/route_handler';
export {Location, APP_BASE_HREF} from './src/router/location'; export {Location, APP_BASE_HREF} from './src/router/location';
export {Pipeline} from './src/router/pipeline'; export {Pipeline} from './src/router/pipeline';
export * from './src/router/route_config_decorator'; export * from './src/router/route_config_decorator';
@ -108,8 +73,6 @@ export const ROUTER_BINDINGS: any[] = CONST_EXPR([
})) }))
]); ]);
export interface InjectableReference {}
function routerFactory(registry, pipeline, location, appRoot) { function routerFactory(registry, pipeline, location, appRoot) {
return new RootRouter(registry, pipeline, location, appRoot); return new RootRouter(registry, pipeline, location, appRoot);
} }

View File

@ -22,13 +22,6 @@ export {
IterableDifferFactory, IterableDifferFactory,
KeyValueDiffers, KeyValueDiffers,
KeyValueDiffer, KeyValueDiffer,
KeyValueDifferFactory, KeyValueDifferFactory
Lexer,
Parser, } from './change_detection/change_detection';
ChangeDispatcher,
BindingTarget,
DirectiveIndex,
DebugContext,
ProtoChangeDetector
} from 'angular2/src/core/change_detection/change_detection';
export * from 'angular2/src/core/change_detection/parser/ast';

View File

@ -14,7 +14,15 @@ import {
import {Injector, Inject, Injectable, OpaqueToken, Optional, Binding} from 'angular2/src/core/di'; import {Injector, Inject, Injectable, OpaqueToken, Optional, Binding} from 'angular2/src/core/di';
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection'; import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {CONST, CONST_EXPR, isPresent, assertionsEnabled} from 'angular2/src/core/facade/lang'; import {CONST, CONST_EXPR, isPresent, assertionsEnabled} from 'angular2/src/core/facade/lang';
export * from './parser/ast';
export {
ASTWithSource,
AST,
AstTransformer,
PropertyRead,
LiteralArray,
ImplicitReceiver
} from './parser/ast';
export {Lexer} from './parser/lexer'; export {Lexer} from './parser/lexer';
export {Parser} from './parser/parser'; export {Parser} from './parser/parser';

View File

@ -19,14 +19,4 @@ export {ElementRef} from './compiler/element_ref';
export {TemplateRef} from './compiler/template_ref'; export {TemplateRef} from './compiler/template_ref';
export {ViewRef, HostViewRef, ProtoViewRef} from './compiler/view_ref'; export {ViewRef, HostViewRef, ProtoViewRef} from './compiler/view_ref';
export {ViewContainerRef} from './compiler/view_container_ref'; export {ViewContainerRef} from './compiler/view_container_ref';
export {AppView, AppProtoView, AppProtoViewMergeMapping, AppViewContainer} from './compiler/view';
export {ComponentRef} from './compiler/dynamic_component_loader'; export {ComponentRef} from './compiler/dynamic_component_loader';
export {
ElementInjector,
PreBuiltObjects,
TreeNode,
ProtoElementInjector,
DirectiveBinding,
EventEmitterAccessor
} from './compiler/element_injector';
export {ElementBinder} from './compiler/element_binder';

View File

@ -16,14 +16,13 @@ import {ElementRef} from 'angular2/src/core/compiler/element_ref';
export class DebugElement { export class DebugElement {
_elementInjector: ElementInjector; _elementInjector: ElementInjector;
/**
* @private
*/
constructor(private _parentView: AppView, private _boundElementIndex: number) { constructor(private _parentView: AppView, private _boundElementIndex: number) {
this._elementInjector = this._parentView.elementInjectors[this._boundElementIndex]; this._elementInjector = this._parentView.elementInjectors[this._boundElementIndex];
} }
static create(elementRef: ElementRef): DebugElement {
return new DebugElement(internalView(elementRef.parentView), elementRef.boundElementIndex);
}
get componentInstance(): any { get componentInstance(): any {
if (!isPresent(this._elementInjector)) { if (!isPresent(this._elementInjector)) {
return null; return null;
@ -144,7 +143,7 @@ export class DebugElement {
* @return {DebugElement} * @return {DebugElement}
*/ */
export function inspectElement(elementRef: ElementRef): DebugElement { export function inspectElement(elementRef: ElementRef): DebugElement {
return DebugElement.create(elementRef); return new DebugElement(internalView(elementRef.parentView), elementRef.boundElementIndex);
} }
export function asNativeElements(arr: DebugElement[]): any[] { export function asNativeElements(arr: DebugElement[]): any[] {

View File

@ -12,5 +12,3 @@ export {LimitToPipe} from './pipes/limit_to_pipe';
export {LowerCasePipe} from './pipes/lowercase_pipe'; export {LowerCasePipe} from './pipes/lowercase_pipe';
export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe'; export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe';
export {UpperCasePipe} from './pipes/uppercase_pipe'; export {UpperCasePipe} from './pipes/uppercase_pipe';
export {ProtoPipes} from './pipes/pipes';
export {PipeBinding} from './pipes/pipe_binding';

View File

@ -12,12 +12,5 @@ export {
ViewDefinition, ViewDefinition,
DOCUMENT, DOCUMENT,
APP_ID, APP_ID,
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE, MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE
EventManager,
SharedStylesHost,
DomSharedStylesHost,
TemplateCloner,
ViewType,
RenderProtoViewMergeMapping,
EventManagerPlugin
} from './render/render'; } from './render/render';

View File

@ -38,6 +38,9 @@ const REFLECT_PREFIX: string = 'ng-reflect-';
export class DomRenderer extends Renderer { export class DomRenderer extends Renderer {
_document; _document;
/**
* @private
*/
constructor(private _eventManager: EventManager, constructor(private _eventManager: EventManager,
private _domSharedStylesHost: DomSharedStylesHost, private _domSharedStylesHost: DomSharedStylesHost,
private _templateCloner: TemplateCloner, @Inject(DOCUMENT) document) { private _templateCloner: TemplateCloner, @Inject(DOCUMENT) document) {

View File

@ -10,7 +10,4 @@ export * from './dom/compiler/compiler';
export * from './dom/dom_renderer'; export * from './dom/dom_renderer';
export * from './dom/dom_tokens'; export * from './dom/dom_tokens';
export * from './dom/template_cloner'; export * from './dom/template_cloner';
export * from './dom/events/event_manager';
export * from './dom/view/shared_styles_host';
export * from './dom/template_cloner';
export * from './api'; export * from './api';

View File

@ -18,6 +18,9 @@ export class JSONPConnection implements Connection {
private _responseData: any; private _responseData: any;
private _finished: boolean = false; private _finished: boolean = false;
/**
* @private
*/
constructor(req: Request, private _dom: BrowserJsonp, constructor(req: Request, private _dom: BrowserJsonp,
private baseResponseOptions?: ResponseOptions) { private baseResponseOptions?: ResponseOptions) {
if (req.method !== RequestMethods.Get) { if (req.method !== RequestMethods.Get) {
@ -91,6 +94,9 @@ export class JSONPConnection implements Connection {
@Injectable() @Injectable()
export class JSONPBackend implements ConnectionBackend { export class JSONPBackend implements ConnectionBackend {
/**
* @private
*/
constructor(private _browserJSONP: BrowserJsonp, private _baseResponseOptions: ResponseOptions) {} constructor(private _browserJSONP: BrowserJsonp, private _baseResponseOptions: ResponseOptions) {}
createConnection(request: Request): JSONPConnection { createConnection(request: Request): JSONPConnection {
return new JSONPConnection(request, this._browserJSONP, this._baseResponseOptions); return new JSONPConnection(request, this._browserJSONP, this._baseResponseOptions);

View File

@ -92,6 +92,9 @@ function stringifyAux(instruction: Instruction): string {
export class ComponentInstruction { export class ComponentInstruction {
reuse: boolean = false; reuse: boolean = false;
/**
* @private
*/
constructor(public urlPath: string, public urlParams: string[], constructor(public urlPath: string, public urlParams: string[],
private _recognizer: PathRecognizer, public params: StringMap<string, any> = null) {} private _recognizer: PathRecognizer, public params: StringMap<string, any> = null) {}

View File

@ -31,6 +31,9 @@ export class RouterOutlet {
private _componentRef: ComponentRef = null; private _componentRef: ComponentRef = null;
private _currentInstruction: ComponentInstruction = null; private _currentInstruction: ComponentInstruction = null;
/**
* @private
*/
constructor(private _elementRef: ElementRef, private _loader: DynamicComponentLoader, constructor(private _elementRef: ElementRef, private _loader: DynamicComponentLoader,
private _parentRouter: routerMod.Router, @Attribute('name') nameAttr: string) { private _parentRouter: routerMod.Router, @Attribute('name') nameAttr: string) {
if (isPresent(nameAttr)) { if (isPresent(nameAttr)) {

View File

@ -22,12 +22,16 @@ import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DebugElement} from 'angular2/src/core/debug/debug_element'; import {DebugElement} from 'angular2/src/core/debug/debug_element';
export class RootTestComponent extends DebugElement { export class RootTestComponent {
_componentRef: ComponentRef; _componentRef: ComponentRef;
_componentParentView: AppView; _componentParentView: AppView;
debugElement: DebugElement;
/**
* @private
*/
constructor(componentRef: ComponentRef) { constructor(componentRef: ComponentRef) {
super(internalView(<ViewRef>componentRef.hostView), 0); this.debugElement = new DebugElement(internalView(<ViewRef>componentRef.hostView), 0);
this._componentParentView = internalView(<ViewRef>componentRef.hostView); this._componentParentView = internalView(<ViewRef>componentRef.hostView);
this._componentRef = componentRef; this._componentRef = componentRef;

View File

@ -16,6 +16,9 @@ export {Type} from "angular2/src/core/facade/lang";
@Injectable() @Injectable()
export class ClientMessageBrokerFactory { export class ClientMessageBrokerFactory {
/**
* @private
*/
constructor(private _messageBus: MessageBus, protected _serializer: Serializer) {} constructor(private _messageBus: MessageBus, protected _serializer: Serializer) {}
/** /**
@ -31,6 +34,9 @@ export class ClientMessageBroker {
private _pending: Map<string, PromiseCompleter<any>> = new Map<string, PromiseCompleter<any>>(); private _pending: Map<string, PromiseCompleter<any>> = new Map<string, PromiseCompleter<any>>();
private _sink: EventEmitter; private _sink: EventEmitter;
/**
* @private
*/
constructor(messageBus: MessageBus, protected _serializer: Serializer, public channel) { constructor(messageBus: MessageBus, protected _serializer: Serializer, public channel) {
this._sink = messageBus.to(channel); this._sink = messageBus.to(channel);
var source = messageBus.from(channel); var source = messageBus.from(channel);

View File

@ -12,6 +12,9 @@ import {
@Injectable() @Injectable()
export class ServiceMessageBrokerFactory { export class ServiceMessageBrokerFactory {
/**
* @private
*/
constructor(private _messageBus: MessageBus, protected _serializer: Serializer) {} constructor(private _messageBus: MessageBus, protected _serializer: Serializer) {}
/** /**
@ -33,6 +36,9 @@ export class ServiceMessageBroker {
private _sink: EventEmitter; private _sink: EventEmitter;
private _methods: Map<string, Function> = new Map<string, Function>(); private _methods: Map<string, Function> = new Map<string, Function>();
/**
* @private
*/
constructor(messageBus: MessageBus, private _serializer: Serializer, public channel) { constructor(messageBus: MessageBus, private _serializer: Serializer, public channel) {
this._sink = messageBus.to(channel); this._sink = messageBus.to(channel);
var source = messageBus.from(channel); var source = messageBus.from(channel);

View File

@ -29,41 +29,42 @@ export function main() {
describe('DynamicComponentLoader', function() { describe('DynamicComponentLoader', function() {
describe("loading into a location", () => { describe("loading into a location", () => {
it('should work', it('should work',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], inject(
(loader, tcb: TestComponentBuilder, async) => { [DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
tcb.overrideView( (loader, tcb: TestComponentBuilder, async) => {
MyComp, tcb.overrideView(
new ViewMetadata( MyComp, new ViewMetadata(
{template: '<location #loc></location>', directives: [Location]})) {template: '<location #loc></location>', directives: [Location]}))
.createAsync(MyComp) .createAsync(MyComp)
.then((tc) => { .then((tc) => {
loader.loadIntoLocation(DynamicallyLoaded, tc.elementRef, 'loc') loader.loadIntoLocation(DynamicallyLoaded, tc.debugElement.elementRef, 'loc')
.then(ref => { .then(ref => {
expect(tc.nativeElement).toHaveText("Location;DynamicallyLoaded;"); expect(tc.debugElement.nativeElement)
async.done(); .toHaveText("Location;DynamicallyLoaded;");
}); async.done();
}); });
})); });
}));
it('should return a disposable component ref', it('should return a disposable component ref',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], inject(
(loader, tcb: TestComponentBuilder, async) => { [DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
tcb.overrideView( (loader, tcb: TestComponentBuilder, async) => {
MyComp, tcb.overrideView(
new ViewMetadata( MyComp, new ViewMetadata(
{template: '<location #loc></location>', directives: [Location]})) {template: '<location #loc></location>', directives: [Location]}))
.createAsync(MyComp) .createAsync(MyComp)
.then((tc) => { .then((tc) => {
loader.loadIntoLocation(DynamicallyLoaded, tc.elementRef, 'loc') loader.loadIntoLocation(DynamicallyLoaded, tc.debugElement.elementRef, 'loc')
.then(ref => { .then(ref => {
ref.dispose(); ref.dispose();
expect(tc.nativeElement).toHaveText("Location;"); expect(tc.debugElement.nativeElement).toHaveText("Location;");
async.done(); async.done();
}); });
}); });
})); }));
it('should allow to dispose even if the location has been removed', it('should allow to dispose even if the location has been removed',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
@ -78,45 +79,48 @@ export function main() {
{template: '<location #loc></location>', directives: [Location]})) {template: '<location #loc></location>', directives: [Location]}))
.createAsync(MyComp) .createAsync(MyComp)
.then((tc) => { .then((tc) => {
tc.componentInstance.ctxBoolProp = true; tc.debugElement.componentInstance.ctxBoolProp = true;
tc.detectChanges(); tc.detectChanges();
var childCompEl = tc.query(By.css('child-cmp')); var childCompEl = tc.debugElement.query(By.css('child-cmp'));
loader.loadIntoLocation(DynamicallyLoaded, childCompEl.elementRef, 'loc') loader.loadIntoLocation(DynamicallyLoaded, childCompEl.elementRef, 'loc')
.then(ref => { .then(ref => {
expect(tc.nativeElement).toHaveText("Location;DynamicallyLoaded;"); expect(tc.debugElement.nativeElement)
.toHaveText("Location;DynamicallyLoaded;");
tc.componentInstance.ctxBoolProp = false; tc.debugElement.componentInstance.ctxBoolProp = false;
tc.detectChanges(); tc.detectChanges();
expect(tc.nativeElement).toHaveText(""); expect(tc.debugElement.nativeElement).toHaveText("");
ref.dispose(); ref.dispose();
expect(tc.nativeElement).toHaveText(""); expect(tc.debugElement.nativeElement).toHaveText("");
async.done(); async.done();
}); });
}); });
})); }));
it('should update host properties', it('should update host properties',
inject( inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], (loader, tcb: TestComponentBuilder, async) => {
(loader, tcb: TestComponentBuilder, async) => { tcb.overrideView(
tcb.overrideView( MyComp,
MyComp, new ViewMetadata( new ViewMetadata(
{template: '<location #loc></location>', directives: [Location]})) {template: '<location #loc></location>', directives: [Location]}))
.createAsync(MyComp) .createAsync(MyComp)
.then((tc) => { .then((tc) => {
loader.loadIntoLocation(DynamicallyLoadedWithHostProps, tc.elementRef, 'loc') loader.loadIntoLocation(DynamicallyLoadedWithHostProps,
.then(ref => { tc.debugElement.elementRef, 'loc')
ref.instance.id = "new value"; .then(ref => {
ref.instance.id = "new value";
tc.detectChanges(); tc.detectChanges();
var newlyInsertedElement = DOM.childNodes(tc.nativeElement)[1]; var newlyInsertedElement =
expect((<HTMLElement>newlyInsertedElement).id).toEqual("new value"); DOM.childNodes(tc.debugElement.nativeElement)[1];
async.done(); expect((<HTMLElement>newlyInsertedElement).id).toEqual("new value");
}); async.done();
}); });
})); });
}));
it('should throw if the variable does not exist', it('should throw if the variable does not exist',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
@ -128,7 +132,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((tc) => { .then((tc) => {
expect(() => loader.loadIntoLocation(DynamicallyLoadedWithHostProps, expect(() => loader.loadIntoLocation(DynamicallyLoadedWithHostProps,
tc.elementRef, 'someUnknownVariable')) tc.debugElement.elementRef,
'someUnknownVariable'))
.toThrowError('Could not find variable someUnknownVariable'); .toThrowError('Could not find variable someUnknownVariable');
async.done(); async.done();
}); });
@ -136,59 +141,60 @@ export function main() {
}); });
describe("loading next to a location", () => { describe("loading next to a location", () => {
it('should work', inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], it('should work',
(loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(
MyComp, new ViewMetadata({
template: '<div><location #loc></location></div>',
directives: [Location]
}))
.createAsync(MyComp)
.then((tc) => {
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef)
.then(ref => {
expect(tc.nativeElement).toHaveText("Location;");
expect(DOM.nextSibling(tc.nativeElement))
.toHaveText('DynamicallyLoaded;');
async.done();
});
});
}));
it('should return a disposable component ref',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => { (loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({ tcb.overrideView(MyComp, new ViewMetadata({
template: '<div><location #loc></location></div>', template: '<div><location #loc></location></div>',
directives: [Location] directives: [Location]
})) }))
. .createAsync(MyComp)
createAsync(MyComp)
.then((tc) => { .then((tc) => {
loader.loadNextToLocation(DynamicallyLoaded, tc.elementRef) loader.loadNextToLocation(DynamicallyLoaded, tc.debugElement.elementRef)
.then(ref => { .then(ref => {
loader.loadNextToLocation(DynamicallyLoaded2, tc.elementRef) expect(tc.debugElement.nativeElement).toHaveText("Location;");
.then(ref2 => { expect(DOM.nextSibling(tc.debugElement.nativeElement))
var firstSibling = DOM.nextSibling(tc.nativeElement); .toHaveText('DynamicallyLoaded;');
var secondSibling = DOM.nextSibling(firstSibling);
expect(tc.nativeElement).toHaveText("Location;");
expect(firstSibling).toHaveText("DynamicallyLoaded;");
expect(secondSibling).toHaveText("DynamicallyLoaded2;");
ref2.dispose(); async.done();
firstSibling = DOM.nextSibling(tc.nativeElement);
secondSibling = DOM.nextSibling(firstSibling);
expect(secondSibling).toBeNull();
async.done();
});
}); });
}); });
})); }));
it('should return a disposable component ref',
inject(
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<div><location #loc></location></div>',
directives: [Location]
}))
.
createAsync(MyComp)
.then((tc) => {
loader.loadNextToLocation(DynamicallyLoaded, tc.debugElement.elementRef)
.then(ref => {
loader.loadNextToLocation(DynamicallyLoaded2, tc.debugElement.elementRef)
.then(ref2 => {
var firstSibling = DOM.nextSibling(tc.debugElement.nativeElement);
var secondSibling = DOM.nextSibling(firstSibling);
expect(tc.debugElement.nativeElement).toHaveText("Location;");
expect(firstSibling).toHaveText("DynamicallyLoaded;");
expect(secondSibling).toHaveText("DynamicallyLoaded2;");
ref2.dispose();
firstSibling = DOM.nextSibling(tc.debugElement.nativeElement);
secondSibling = DOM.nextSibling(firstSibling);
expect(secondSibling).toBeNull();
async.done();
});
});
});
}));
it('should update host properties', it('should update host properties',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter], inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => { (loader, tcb: TestComponentBuilder, async) => {
@ -200,13 +206,15 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((tc) => { .then((tc) => {
loader.loadNextToLocation(DynamicallyLoadedWithHostProps, tc.elementRef) loader.loadNextToLocation(DynamicallyLoadedWithHostProps,
tc.debugElement.elementRef)
.then(ref => { .then(ref => {
ref.instance.id = "new value"; ref.instance.id = "new value";
tc.detectChanges(); tc.detectChanges();
var newlyInsertedElement = DOM.nextSibling(tc.nativeElement); var newlyInsertedElement =
DOM.nextSibling(tc.debugElement.nativeElement);
expect((<HTMLElement>newlyInsertedElement).id).toEqual("new value"); expect((<HTMLElement>newlyInsertedElement).id).toEqual("new value");
async.done(); async.done();

View File

@ -56,7 +56,7 @@ main() {
.createAsync(Dummy) .createAsync(Dummy)
.then((tc) { .then((tc) {
tc.detectChanges(); tc.detectChanges();
expect(asNativeElements(tc.componentViewChildren)) expect(asNativeElements(tc.debugElement.componentViewChildren))
.toHaveText('[Hello, World]'); .toHaveText('[Hello, World]');
async.done(); async.done();
}); });
@ -112,7 +112,7 @@ main() {
.createAsync(Dummy) .createAsync(Dummy)
.then((tc) { .then((tc) {
tc.detectChanges(); tc.detectChanges();
expect(asNativeElements(tc.componentViewChildren)) expect(asNativeElements(tc.debugElement.componentViewChildren))
.toHaveText('prop:foo-prop;map:foo-map'); .toHaveText('prop:foo-prop;map:foo-map');
async.done(); async.done();
}); });
@ -149,7 +149,7 @@ main() {
.createAsync(Dummy) .createAsync(Dummy)
.then((tc) { .then((tc) {
tc.detectChanges(); tc.detectChanges();
var cmp = tc.componentViewChildren[0].inject(OnChangeComponent); var cmp = tc.debugElement.componentViewChildren[0].inject(OnChangeComponent);
expect(cmp.prop).toEqual('hello'); expect(cmp.prop).toEqual('hello');
expect(cmp.changes.containsKey('prop')).toEqual(true); expect(cmp.changes.containsKey('prop')).toEqual(true);
async.done(); async.done();
@ -171,19 +171,19 @@ main() {
directives: [ComponentWithObservableList])) directives: [ComponentWithObservableList]))
.createAsync(Dummy) .createAsync(Dummy)
.then((tc) { .then((tc) {
tc.componentInstance.value = new ObservableList.from([1, 2]); tc.debugElement.componentInstance.value = new ObservableList.from([1, 2]);
tc.detectChanges(); tc.detectChanges();
expect(log.result()).toEqual("check"); expect(log.result()).toEqual("check");
expect(asNativeElements(tc.componentViewChildren)).toHaveText('12'); expect(asNativeElements(tc.debugElement.componentViewChildren)).toHaveText('12');
tc.detectChanges(); tc.detectChanges();
// we did not change the list => no checks // we did not change the list => no checks
expect(log.result()).toEqual("check"); expect(log.result()).toEqual("check");
tc.componentInstance.value.add(3); tc.debugElement.componentInstance.value.add(3);
flushMicrotasks(); flushMicrotasks();
@ -191,16 +191,16 @@ main() {
// we changed the list => a check // we changed the list => a check
expect(log.result()).toEqual("check; check"); expect(log.result()).toEqual("check; check");
expect(asNativeElements(tc.componentViewChildren)) expect(asNativeElements(tc.debugElement.componentViewChildren))
.toHaveText('123'); .toHaveText('123');
// we replaced the list => a check // we replaced the list => a check
tc.componentInstance.value = new ObservableList.from([5, 6, 7]); tc.debugElement.componentInstance.value = new ObservableList.from([5, 6, 7]);
tc.detectChanges(); tc.detectChanges();
expect(log.result()).toEqual("check; check; check"); expect(log.result()).toEqual("check; check; check");
expect(asNativeElements(tc.componentViewChildren)) expect(asNativeElements(tc.debugElement.componentViewChildren))
.toHaveText('567'); .toHaveText('567');
}); });
}))); })));

View File

@ -17,7 +17,8 @@ import {
TestComponentBuilder, TestComponentBuilder,
fakeAsync, fakeAsync,
tick, tick,
clearPendingTimers clearPendingTimers,
RootTestComponent
} from 'angular2/test_lib'; } from 'angular2/test_lib';
@ -105,10 +106,10 @@ export function main() {
tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{ctxProp}}</div>'})) tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{ctxProp}}</div>'}))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Hello World!'; rootTC.debugElement.componentInstance.ctxProp = 'Hello World!';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('Hello World!'); expect(rootTC.debugElement.nativeElement).toHaveText('Hello World!');
async.done(); async.done();
}); });
@ -119,10 +120,10 @@ export function main() {
tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{null}}{{ctxProp}}</div>'})) tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{null}}{{ctxProp}}</div>'}))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = null; rootTC.debugElement.componentInstance.ctxProp = null;
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(''); expect(rootTC.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
})); }));
@ -133,10 +134,11 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Hello World!'; rootTC.debugElement.componentInstance.ctxProp = 'Hello World!';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[0].nativeElement.id).toEqual('Hello World!'); expect(rootTC.debugElement.componentViewChildren[0].nativeElement.id)
.toEqual('Hello World!');
async.done(); async.done();
}); });
})); }));
@ -149,16 +151,16 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Initial aria label'; rootTC.debugElement.componentInstance.ctxProp = 'Initial aria label';
rootTC.detectChanges(); rootTC.detectChanges();
expect( expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
DOM.getAttribute(rootTC.componentViewChildren[0].nativeElement, 'aria-label')) 'aria-label'))
.toEqual('Initial aria label'); .toEqual('Initial aria label');
rootTC.componentInstance.ctxProp = 'Changed aria label'; rootTC.debugElement.componentInstance.ctxProp = 'Changed aria label';
rootTC.detectChanges(); rootTC.detectChanges();
expect( expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
DOM.getAttribute(rootTC.componentViewChildren[0].nativeElement, 'aria-label')) 'aria-label'))
.toEqual('Changed aria label'); .toEqual('Changed aria label');
async.done(); async.done();
@ -174,11 +176,13 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[0].nativeElement.tabIndex).toEqual(0); expect(rootTC.debugElement.componentViewChildren[0].nativeElement.tabIndex)
.toEqual(0);
rootTC.componentInstance.ctxNumProp = 5; rootTC.debugElement.componentInstance.ctxNumProp = 5;
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[0].nativeElement.tabIndex).toEqual(5); expect(rootTC.debugElement.componentViewChildren[0].nativeElement.tabIndex)
.toEqual(5);
async.done(); async.done();
}); });
@ -193,11 +197,13 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[0].nativeElement.readOnly).toBeFalsy(); expect(rootTC.debugElement.componentViewChildren[0].nativeElement.readOnly)
.toBeFalsy();
rootTC.componentInstance.ctxBoolProp = true; rootTC.debugElement.componentInstance.ctxBoolProp = true;
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[0].nativeElement.readOnly).toBeTruthy(); expect(rootTC.debugElement.componentViewChildren[0].nativeElement.readOnly)
.toBeTruthy();
async.done(); async.done();
}); });
@ -211,14 +217,16 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Some <span>HTML</span>'; rootTC.debugElement.componentInstance.ctxProp = 'Some <span>HTML</span>';
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getInnerHTML(rootTC.componentViewChildren[0].nativeElement)) expect(
DOM.getInnerHTML(rootTC.debugElement.componentViewChildren[0].nativeElement))
.toEqual('Some <span>HTML</span>'); .toEqual('Some <span>HTML</span>');
rootTC.componentInstance.ctxProp = 'Some other <div>HTML</div>'; rootTC.debugElement.componentInstance.ctxProp = 'Some other <div>HTML</div>';
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getInnerHTML(rootTC.componentViewChildren[0].nativeElement)) expect(
DOM.getInnerHTML(rootTC.debugElement.componentViewChildren[0].nativeElement))
.toEqual('Some other <div>HTML</div>'); .toEqual('Some other <div>HTML</div>');
async.done(); async.done();
@ -233,8 +241,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var nativeEl = rootTC.componentViewChildren[0].nativeElement; var nativeEl = rootTC.debugElement.componentViewChildren[0].nativeElement;
rootTC.componentInstance.ctxProp = 'foo bar'; rootTC.debugElement.componentInstance.ctxProp = 'foo bar';
rootTC.detectChanges(); rootTC.detectChanges();
expect(nativeEl).toHaveCssClass('foo'); expect(nativeEl).toHaveCssClass('foo');
@ -258,14 +266,16 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Hello World!'; rootTC.debugElement.componentInstance.ctxProp = 'Hello World!';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[0].inject(MyDir).dirProp) expect(rootTC.debugElement.componentViewChildren[0].inject(MyDir).dirProp)
.toEqual('Hello World!'); .toEqual('Hello World!');
expect(rootTC.componentViewChildren[1].inject(MyDir).dirProp).toEqual('Hi there!'); expect(rootTC.debugElement.componentViewChildren[1].inject(MyDir).dirProp)
expect(rootTC.componentViewChildren[2].inject(MyDir).dirProp).toEqual('Hi there!'); .toEqual('Hi there!');
expect(rootTC.componentViewChildren[3].inject(MyDir).dirProp) expect(rootTC.debugElement.componentViewChildren[2].inject(MyDir).dirProp)
.toEqual('Hi there!');
expect(rootTC.debugElement.componentViewChildren[3].inject(MyDir).dirProp)
.toEqual('One more Hello World!'); .toEqual('One more Hello World!');
async.done(); async.done();
}); });
@ -284,10 +294,10 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'a'; rootTC.debugElement.componentInstance.ctxProp = 'a';
rootTC.detectChanges(); rootTC.detectChanges();
var dir = rootTC.componentViewChildren[0].getLocal('dir'); var dir = rootTC.debugElement.componentViewChildren[0].getLocal('dir');
expect(dir.dirProp).toEqual('aa'); expect(dir.dirProp).toEqual('aa');
async.done(); async.done();
}); });
@ -305,7 +315,7 @@ export function main() {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello'); expect(rootTC.debugElement.nativeElement).toHaveText('hello');
async.done(); async.done();
}); });
})); }));
@ -321,10 +331,10 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Hello World!'; rootTC.debugElement.componentInstance.ctxProp = 'Hello World!';
rootTC.detectChanges(); rootTC.detectChanges();
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
expect(tc.inject(MyDir).dirProp).toEqual('Hello World!'); expect(tc.inject(MyDir).dirProp).toEqual('Hello World!');
expect(tc.inject(ChildComp).dirProp).toEqual(null); expect(tc.inject(ChildComp).dirProp).toEqual(null);
@ -358,7 +368,7 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.nativeElement).toHaveText('noduplicate'); expect(rootTC.debugElement.nativeElement).toHaveText('noduplicate');
async.done(); async.done();
}); });
})); }));
@ -375,7 +385,7 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.nativeElement).toHaveText('othernoduplicate'); expect(rootTC.debugElement.nativeElement).toHaveText('othernoduplicate');
async.done(); async.done();
}); });
})); }));
@ -387,14 +397,14 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var idDir = tc.inject(IdDir); var idDir = tc.inject(IdDir);
rootTC.componentInstance.ctxProp = 'some_id'; rootTC.debugElement.componentInstance.ctxProp = 'some_id';
rootTC.detectChanges(); rootTC.detectChanges();
expect(idDir.id).toEqual('some_id'); expect(idDir.id).toEqual('some_id');
rootTC.componentInstance.ctxProp = 'other_id'; rootTC.debugElement.componentInstance.ctxProp = 'other_id';
rootTC.detectChanges(); rootTC.detectChanges();
expect(idDir.id).toEqual('other_id'); expect(idDir.id).toEqual('other_id');
@ -413,7 +423,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello'); expect(rootTC.debugElement.nativeElement).toHaveText('hello');
async.done(); async.done();
}); });
})); }));
@ -443,7 +453,7 @@ export function main() {
rootTC.detectChanges(); rootTC.detectChanges();
var childNodesOfWrapper = rootTC.componentViewChildren; var childNodesOfWrapper = rootTC.debugElement.componentViewChildren;
// 1 template + 2 copies. // 1 template + 2 copies.
expect(childNodesOfWrapper.length).toBe(3); expect(childNodesOfWrapper.length).toBe(3);
expect(childNodesOfWrapper[1].nativeElement).toHaveText('hello'); expect(childNodesOfWrapper[1].nativeElement).toHaveText('hello');
@ -465,7 +475,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
var childNodesOfWrapper = rootTC.componentViewChildren; var childNodesOfWrapper = rootTC.debugElement.componentViewChildren;
// 1 template + 2 copies. // 1 template + 2 copies.
expect(childNodesOfWrapper.length).toBe(3); expect(childNodesOfWrapper.length).toBe(3);
expect(childNodesOfWrapper[1].nativeElement).toHaveText('hello'); expect(childNodesOfWrapper[1].nativeElement).toHaveText('hello');
@ -484,10 +494,10 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'From myComp'; rootTC.debugElement.componentInstance.ctxProp = 'From myComp';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement) expect(rootTC.debugElement.nativeElement)
.toHaveText( .toHaveText(
'TOOLBAR(From myComp,From toolbar,Component with an injected host)'); 'TOOLBAR(From myComp,From toolbar,Component with an injected host)');
@ -506,7 +516,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.componentViewChildren[0].getLocal('alice')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('alice'))
.toBeAnInstanceOf(ChildComp); .toBeAnInstanceOf(ChildComp);
async.done(); async.done();
@ -522,7 +532,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.componentViewChildren[0].getLocal('localdir')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('localdir'))
.toBeAnInstanceOf(ExportDir); .toBeAnInstanceOf(ExportDir);
async.done(); async.done();
@ -543,7 +553,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement) expect(rootTC.debugElement.nativeElement)
.toHaveText('hellohello'); // this first one is the .toHaveText('hellohello'); // this first one is the
// component, the second one is // component, the second one is
// the text binding // the text binding
@ -563,32 +573,33 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.componentViewChildren[0].getLocal('alice')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('alice'))
.toBeAnInstanceOf(ChildComp); .toBeAnInstanceOf(ChildComp);
expect(rootTC.componentViewChildren[0].getLocal('bob')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('bob'))
.toBeAnInstanceOf(ChildComp); .toBeAnInstanceOf(ChildComp);
expect(rootTC.componentViewChildren[0].getLocal('alice')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('alice'))
.not.toBe(rootTC.componentViewChildren[0].getLocal('bob')); .not.toBe(
rootTC.debugElement.componentViewChildren[0].getLocal('bob'));
async.done(); async.done();
})})); })}));
it('should assign the component instance to a var- with shorthand syntax', it('should assign the component instance to a var- with shorthand syntax',
inject([TestComponentBuilder, AsyncTestCompleter], inject([TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, (tcb: TestComponentBuilder, async) => {
async) => {tcb.overrideView(MyComp, new ViewMetadata({ tcb.overrideView(MyComp, new ViewMetadata({
template: '<child-cmp #alice></child-cmp>', template: '<child-cmp #alice></child-cmp>',
directives: [ChildComp] directives: [ChildComp]
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.componentViewChildren[0].getLocal('alice')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('alice'))
.toBeAnInstanceOf(ChildComp); .toBeAnInstanceOf(ChildComp);
async.done(); async.done();
})})); })}));
it('should assign the element instance to a user-defined variable', it('should assign the element instance to a user-defined variable',
inject([TestComponentBuilder, AsyncTestCompleter], inject([TestComponentBuilder, AsyncTestCompleter],
@ -600,7 +611,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var value = rootTC.componentViewChildren[0].getLocal('alice'); var value =
rootTC.debugElement.componentViewChildren[0].getLocal('alice');
expect(value).not.toBe(null); expect(value).not.toBe(null);
expect(value.tagName.toLowerCase()).toEqual('div'); expect(value.tagName.toLowerCase()).toEqual('div');
@ -608,21 +620,21 @@ export function main() {
})})); })}));
it('should change dash-case to camel-case', it('should change dash-case to camel-case',
inject([TestComponentBuilder, AsyncTestCompleter], inject(
(tcb: TestComponentBuilder, async) => { [TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({ tcb.overrideView(MyComp, new ViewMetadata({
template: '<p><child-cmp var-super-alice></child-cmp></p>', template: '<p><child-cmp var-super-alice></child-cmp></p>',
directives: [ChildComp] directives: [ChildComp]
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.componentViewChildren[0].getLocal('superAlice')) expect(rootTC.debugElement.componentViewChildren[0].getLocal('superAlice'))
.toBeAnInstanceOf(ChildComp); .toBeAnInstanceOf(ChildComp);
async.done(); async.done();
}); });
})); }));
it('should allow to use variables in a for loop', it('should allow to use variables in a for loop',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
@ -639,7 +651,8 @@ export function main() {
rootTC.detectChanges(); rootTC.detectChanges();
// Get the element at index 1, since index 0 is the <template>. // Get the element at index 1, since index 0 is the <template>.
expect(rootTC.componentViewChildren[1].nativeElement).toHaveText("1-hello"); expect(rootTC.debugElement.componentViewChildren[1].nativeElement)
.toHaveText("1-hello");
async.done(); async.done();
}); });
@ -659,7 +672,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var cmp = rootTC.componentViewChildren[0].getLocal('cmp'); var cmp = rootTC.debugElement.componentViewChildren[0].getLocal('cmp');
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmp.numberOfChecks).toEqual(1); expect(cmp.numberOfChecks).toEqual(1);
@ -685,13 +698,13 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var cmp = rootTC.componentViewChildren[0].getLocal('cmp'); var cmp = rootTC.debugElement.componentViewChildren[0].getLocal('cmp');
rootTC.componentInstance.ctxProp = "one"; rootTC.debugElement.componentInstance.ctxProp = "one";
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmp.numberOfChecks).toEqual(1); expect(cmp.numberOfChecks).toEqual(1);
rootTC.componentInstance.ctxProp = "two"; rootTC.debugElement.componentInstance.ctxProp = "two";
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmp.numberOfChecks).toEqual(2); expect(cmp.numberOfChecks).toEqual(2);
@ -711,13 +724,13 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var cmp = rootTC.componentViewChildren[0].getLocal('cmp'); var cmp = rootTC.debugElement.componentViewChildren[0].getLocal('cmp');
rootTC.componentInstance.ctxProp = "one"; rootTC.debugElement.componentInstance.ctxProp = "one";
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmp.prop).toEqual("one"); expect(cmp.prop).toEqual("one");
rootTC.componentInstance.ctxProp = "two"; rootTC.debugElement.componentInstance.ctxProp = "two";
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmp.prop).toEqual("two"); expect(cmp.prop).toEqual("two");
@ -733,11 +746,11 @@ export function main() {
directives: [[[PushCmpWithAsyncPipe]]] directives: [[[PushCmpWithAsyncPipe]]]
})); }));
var rootTC; var rootTC: RootTestComponent;
tcb.createAsync(MyComp).then(root => { rootTC = root; }); tcb.createAsync(MyComp).then(root => { rootTC = root; });
tick(); tick();
var cmp = rootTC.componentViewChildren[0].getLocal('cmp'); var cmp = rootTC.debugElement.componentViewChildren[0].getLocal('cmp');
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmp.numberOfChecks).toEqual(1); expect(cmp.numberOfChecks).toEqual(1);
@ -770,7 +783,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var childComponent = rootTC.componentViewChildren[0].getLocal('child'); var childComponent =
rootTC.debugElement.componentViewChildren[0].getLocal('child');
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective); expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
async.done(); async.done();
@ -792,7 +806,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
var tc = rootTC.componentViewChildren[0].children[1]; var tc = rootTC.debugElement.componentViewChildren[0].children[1];
var childComponent = tc.getLocal('child'); var childComponent = tc.getLocal('child');
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective); expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
@ -811,7 +825,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var emitter = tc.inject(DirectiveEmitingEvent); var emitter = tc.inject(DirectiveEmitingEvent);
var listener = tc.inject(DirectiveListeningEvent); var listener = tc.inject(DirectiveListeningEvent);
@ -835,16 +849,16 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var dir = tc.inject(DirectiveWithTwoWayBinding); var dir = tc.inject(DirectiveWithTwoWayBinding);
rootTC.componentInstance.ctxProp = 'one'; rootTC.debugElement.componentInstance.ctxProp = 'one';
rootTC.detectChanges(); rootTC.detectChanges();
expect(dir.value).toEqual('one'); expect(dir.value).toEqual('one');
ObservableWrapper.subscribe(dir.control, (_) => { ObservableWrapper.subscribe(dir.control, (_) => {
expect(rootTC.componentInstance.ctxProp).toEqual('two'); expect(rootTC.debugElement.componentInstance.ctxProp).toEqual('two');
async.done(); async.done();
}); });
@ -862,7 +876,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var listener = tc.inject(DirectiveListeningDomEvent); var listener = tc.inject(DirectiveListeningDomEvent);
dispatchEvent(tc.nativeElement, 'domEvent'); dispatchEvent(tc.nativeElement, 'domEvent');
@ -884,7 +898,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var listener = tc.inject(DirectiveListeningDomEvent); var listener = tc.inject(DirectiveListeningDomEvent);
dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent');
expect(listener.eventTypes).toEqual(['window_domEvent']); expect(listener.eventTypes).toEqual(['window_domEvent']);
@ -913,7 +927,8 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.componentViewChildren[0].nativeElement, "role")) expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
"role"))
.toEqual("button"); .toEqual("button");
async.done(); async.done();
@ -929,7 +944,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var updateHost = tc.inject(DirectiveUpdatingHostProperties); var updateHost = tc.inject(DirectiveUpdatingHostProperties);
updateHost.id = "newId"; updateHost.id = "newId";
@ -961,15 +976,17 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
var dispatchedEvent = DOM.createMouseEvent('click'); var dispatchedEvent = DOM.createMouseEvent('click');
var dispatchedEvent2 = DOM.createMouseEvent('click'); var dispatchedEvent2 = DOM.createMouseEvent('click');
DOM.dispatchEvent(rootTC.componentViewChildren[0].nativeElement, DOM.dispatchEvent(rootTC.debugElement.componentViewChildren[0].nativeElement,
dispatchedEvent); dispatchedEvent);
DOM.dispatchEvent(rootTC.componentViewChildren[1].nativeElement, DOM.dispatchEvent(rootTC.debugElement.componentViewChildren[1].nativeElement,
dispatchedEvent2); dispatchedEvent2);
expect(DOM.isPrevented(dispatchedEvent)).toBe(true); expect(DOM.isPrevented(dispatchedEvent)).toBe(true);
expect(DOM.isPrevented(dispatchedEvent2)).toBe(false); expect(DOM.isPrevented(dispatchedEvent2)).toBe(false);
expect(DOM.getChecked(rootTC.componentViewChildren[0].nativeElement)) expect(
DOM.getChecked(rootTC.debugElement.componentViewChildren[0].nativeElement))
.toBeFalsy(); .toBeFalsy();
expect(DOM.getChecked(rootTC.componentViewChildren[1].nativeElement)) expect(
DOM.getChecked(rootTC.debugElement.componentViewChildren[1].nativeElement))
.toBeTruthy(); .toBeTruthy();
async.done(); async.done();
}); });
@ -988,10 +1005,10 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
globalCounter = 0; globalCounter = 0;
rootTC.componentInstance.ctxBoolProp = true; rootTC.debugElement.componentInstance.ctxBoolProp = true;
rootTC.detectChanges(); rootTC.detectChanges();
var tc = rootTC.componentViewChildren[1]; var tc = rootTC.debugElement.componentViewChildren[1];
var listener = tc.inject(DirectiveListeningDomEvent); var listener = tc.inject(DirectiveListeningDomEvent);
var listenerother = tc.inject(DirectiveListeningDomEventOther); var listenerother = tc.inject(DirectiveListeningDomEventOther);
@ -1001,12 +1018,12 @@ export function main() {
expect(globalCounter).toEqual(1); expect(globalCounter).toEqual(1);
rootTC.componentInstance.ctxBoolProp = false; rootTC.debugElement.componentInstance.ctxBoolProp = false;
rootTC.detectChanges(); rootTC.detectChanges();
dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent');
expect(globalCounter).toEqual(1); expect(globalCounter).toEqual(1);
rootTC.componentInstance.ctxBoolProp = true; rootTC.debugElement.componentInstance.ctxBoolProp = true;
rootTC.detectChanges(); rootTC.detectChanges();
dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent');
expect(globalCounter).toEqual(2); expect(globalCounter).toEqual(2);
@ -1027,11 +1044,11 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var dynamicVp = tc.inject(DynamicViewport); var dynamicVp = tc.inject(DynamicViewport);
dynamicVp.done.then((_) => { dynamicVp.done.then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[1].nativeElement) expect(rootTC.debugElement.componentViewChildren[1].nativeElement)
.toHaveText('dynamic greet'); .toHaveText('dynamic greet');
async.done(); async.done();
}); });
@ -1048,7 +1065,7 @@ export function main() {
{template: '<input static type="text" title>', directives: [NeedsAttribute]})) {template: '<input static type="text" title>', directives: [NeedsAttribute]}))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
var needsAttribute = tc.inject(NeedsAttribute); var needsAttribute = tc.inject(NeedsAttribute);
expect(needsAttribute.typeAttribute).toEqual('text'); expect(needsAttribute.typeAttribute).toEqual('text');
expect(needsAttribute.staticAttribute).toEqual(''); expect(needsAttribute.staticAttribute).toEqual('');
@ -1074,7 +1091,7 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var comp = rootTC.componentViewChildren[0].getLocal("consuming"); var comp = rootTC.debugElement.componentViewChildren[0].getLocal("consuming");
expect(comp.injectable).toBeAnInstanceOf(InjectableService); expect(comp.injectable).toBeAnInstanceOf(InjectableService);
async.done(); async.done();
@ -1092,7 +1109,7 @@ export function main() {
})) }))
.createAsync(DirectiveProvidingInjectableInView) .createAsync(DirectiveProvidingInjectableInView)
.then((rootTC) => { .then((rootTC) => {
var comp = rootTC.componentViewChildren[0].getLocal("consuming"); var comp = rootTC.debugElement.componentViewChildren[0].getLocal("consuming");
expect(comp.injectable).toBeAnInstanceOf(InjectableService); expect(comp.injectable).toBeAnInstanceOf(InjectableService);
async.done(); async.done();
@ -1122,7 +1139,7 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var comp = rootTC.componentViewChildren[0].getLocal("dir"); var comp = rootTC.debugElement.componentViewChildren[0].getLocal("dir");
expect(comp.directive.injectable).toBeAnInstanceOf(InjectableService); expect(comp.directive.injectable).toBeAnInstanceOf(InjectableService);
async.done(); async.done();
@ -1148,7 +1165,7 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var gpComp = rootTC.componentViewChildren[0]; var gpComp = rootTC.debugElement.componentViewChildren[0];
var parentComp = gpComp.children[0]; var parentComp = gpComp.children[0];
var childComp = parentComp.children[0]; var childComp = parentComp.children[0];
@ -1180,10 +1197,10 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
var providing = rootTC.componentViewChildren[0].getLocal("providing"); var providing = rootTC.debugElement.componentViewChildren[0].getLocal("providing");
expect(providing.created).toBe(false); expect(providing.created).toBe(false);
rootTC.componentInstance.ctxBoolProp = true; rootTC.debugElement.componentInstance.ctxBoolProp = true;
rootTC.detectChanges(); rootTC.detectChanges();
expect(providing.created).toBe(true); expect(providing.created).toBe(true);
@ -1203,7 +1220,8 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(DOM.querySelectorAll(rootTC.nativeElement, 'script').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'script').length)
.toEqual(0);
async.done(); async.done();
}); });
})); }));
@ -1281,7 +1299,7 @@ export function main() {
expect(DOM.nodeName(c.componentElement).toUpperCase()).toEqual("DIV"); expect(DOM.nodeName(c.componentElement).toUpperCase()).toEqual("DIV");
expect(c.injector).toBeAnInstanceOf(Injector); expect(c.injector).toBeAnInstanceOf(Injector);
expect(c.expression).toContain("one.two.three"); expect(c.expression).toContain("one.two.three");
expect(c.context).toBe(rootTC.componentInstance); expect(c.context).toBe(rootTC.debugElement.componentInstance);
expect(c.locals["local"]).toBeDefined(); expect(c.locals["local"]).toBeDefined();
} }
@ -1318,11 +1336,11 @@ export function main() {
directives: [DirectiveEmitingEvent, DirectiveListeningEvent] directives: [DirectiveEmitingEvent, DirectiveListeningEvent]
})); }));
var rootTC; var rootTC: RootTestComponent;
tcb.createAsync(MyComp).then(root => { rootTC = root; }); tcb.createAsync(MyComp).then(root => { rootTC = root; });
tick(); tick();
var tc = rootTC.componentViewChildren[0]; var tc = rootTC.debugElement.componentViewChildren[0];
tc.inject(DirectiveEmitingEvent).fireEvent("boom"); tc.inject(DirectiveEmitingEvent).fireEvent("boom");
try { try {
@ -1335,7 +1353,7 @@ export function main() {
expect(DOM.nodeName(c.element).toUpperCase()).toEqual("SPAN"); expect(DOM.nodeName(c.element).toUpperCase()).toEqual("SPAN");
expect(DOM.nodeName(c.componentElement).toUpperCase()).toEqual("DIV"); expect(DOM.nodeName(c.componentElement).toUpperCase()).toEqual("DIV");
expect(c.injector).toBeAnInstanceOf(Injector); expect(c.injector).toBeAnInstanceOf(Injector);
expect(c.context).toBe(rootTC.componentInstance); expect(c.context).toBe(rootTC.debugElement.componentInstance);
expect(c.locals["local"]).toBeDefined(); expect(c.locals["local"]).toBeDefined();
} }
}))); })));
@ -1411,7 +1429,7 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
expect(rootTC.nativeElement).toHaveText('hello imp view'); expect(rootTC.debugElement.nativeElement).toHaveText('hello imp view');
async.done(); async.done();
}); });
})); }));
@ -1424,18 +1442,18 @@ export function main() {
directives: [SomeImperativeViewport] directives: [SomeImperativeViewport]
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC: RootTestComponent) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(anchorElement).toHaveText(''); expect(anchorElement).toHaveText('');
rootTC.componentInstance.ctxBoolProp = true; rootTC.debugElement.componentInstance.ctxBoolProp = true;
rootTC.detectChanges(); rootTC.detectChanges();
expect(anchorElement).toHaveText('hello'); expect(anchorElement).toHaveText('hello');
rootTC.componentInstance.ctxBoolProp = false; rootTC.debugElement.componentInstance.ctxBoolProp = false;
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(''); expect(rootTC.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
@ -1478,10 +1496,10 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = "TITLE"; rootTC.debugElement.componentInstance.ctxProp = "TITLE";
rootTC.detectChanges(); rootTC.detectChanges();
var el = DOM.querySelector(rootTC.nativeElement, "span"); var el = DOM.querySelector(rootTC.debugElement.nativeElement, "span");
expect(isBlank(el.title) || el.title == '').toBeTruthy(); expect(isBlank(el.title) || el.title == '').toBeTruthy();
async.done(); async.done();
@ -1497,10 +1515,10 @@ export function main() {
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = "TITLE"; rootTC.debugElement.componentInstance.ctxProp = "TITLE";
rootTC.detectChanges(); rootTC.detectChanges();
var el = DOM.querySelector(rootTC.nativeElement, "span"); var el = DOM.querySelector(rootTC.debugElement.nativeElement, "span");
expect(el.title).toEqual("TITLE"); expect(el.title).toEqual("TITLE");
async.done(); async.done();
@ -1525,10 +1543,10 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'hello'; rootTC.debugElement.componentInstance.ctxProp = 'hello';
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getInnerHTML(rootTC.nativeElement)) expect(DOM.getInnerHTML(rootTC.debugElement.nativeElement))
.toContain('ng-reflect-dir-prop="hello"'); .toContain('ng-reflect-dir-prop="hello"');
async.done(); async.done();
}); });
@ -1543,10 +1561,10 @@ export function main() {
new ViewMetadata({template: `<!--${mode}--><div>{{ctxProp}}</div>`})) new ViewMetadata({template: `<!--${mode}--><div>{{ctxProp}}</div>`}))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.ctxProp = 'Hello World!'; rootTC.debugElement.componentInstance.ctxProp = 'Hello World!';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('Hello World!'); expect(rootTC.debugElement.nativeElement).toHaveText('Hello World!');
async.done(); async.done();
}); });
}); });
@ -1621,7 +1639,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
var dir = rootTC.componentViewChildren[0].inject(DirectiveWithPropDecorators); var dir = rootTC.debugElement.componentViewChildren[0].inject(
DirectiveWithPropDecorators);
expect(dir.dirProp).toEqual("aaa"); expect(dir.dirProp).toEqual("aaa");
async.done(); async.done();
}); });
@ -1636,11 +1655,13 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
var dir = rootTC.componentViewChildren[0].inject(DirectiveWithPropDecorators); var dir = rootTC.debugElement.componentViewChildren[0].inject(
DirectiveWithPropDecorators);
dir.myAttr = "aaa"; dir.myAttr = "aaa";
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getOuterHTML(rootTC.componentViewChildren[0].nativeElement)) expect(
DOM.getOuterHTML(rootTC.debugElement.componentViewChildren[0].nativeElement))
.toContain('my-attr="aaa"'); .toContain('my-attr="aaa"');
async.done(); async.done();
}); });
@ -1655,38 +1676,39 @@ export function main() {
directives: [DirectiveWithPropDecorators] directives: [DirectiveWithPropDecorators]
})); }));
var rootTC; var rootTC: RootTestComponent;
tcb.createAsync(MyComp).then(root => { rootTC = root; }); tcb.createAsync(MyComp).then(root => { rootTC = root; });
tick(); tick();
var emitter = var emitter = rootTC.debugElement.componentViewChildren[0].inject(
rootTC.componentViewChildren[0].inject(DirectiveWithPropDecorators); DirectiveWithPropDecorators);
emitter.fireEvent('fired !'); emitter.fireEvent('fired !');
tick(); tick();
expect(rootTC.componentInstance.ctxProp).toEqual("called"); expect(rootTC.debugElement.componentInstance.ctxProp).toEqual("called");
}))); })));
it('should support host listener decorators', it('should support host listener decorators',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, inject([TestComponentBuilder, AsyncTestCompleter],
async) => { (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({ tcb.overrideView(MyComp, new ViewMetadata({
template: '<with-prop-decorators></with-prop-decorators>', template: '<with-prop-decorators></with-prop-decorators>',
directives: [DirectiveWithPropDecorators] directives: [DirectiveWithPropDecorators]
})) }))
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
var dir = rootTC.componentViewChildren[0].inject(DirectiveWithPropDecorators); var dir = rootTC.debugElement.componentViewChildren[0].inject(
var native = rootTC.componentViewChildren[0].nativeElement; DirectiveWithPropDecorators);
native.click(); var native = rootTC.debugElement.componentViewChildren[0].nativeElement;
native.click();
expect(dir.target).toBe(native); expect(dir.target).toBe(native);
async.done(); async.done();
}); });
})); }));
} }
}); });
}); });
@ -2255,4 +2277,4 @@ class DirectiveWithPropDecorators {
} }
fireEvent(msg) { ObservableWrapper.callNext(this.event, msg); } fireEvent(msg) { ObservableWrapper.callNext(this.event, msg); }
} }

View File

@ -49,7 +49,7 @@ export function main() {
})) }))
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText('SIMPLE(A)'); expect(main.debugElement.nativeElement).toHaveText('SIMPLE(A)');
async.done(); async.done();
}); });
})); }));
@ -65,9 +65,9 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
main.componentInstance.text = 'A'; main.debugElement.componentInstance.text = 'A';
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('START(SIMPLE(A))END'); expect(main.debugElement.nativeElement).toHaveText('START(SIMPLE(A))END');
async.done(); async.done();
}); });
})); }));
@ -84,9 +84,9 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
main.componentInstance.text = 'A'; main.debugElement.componentInstance.text = 'A';
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('SIMPLE(A)'); expect(main.debugElement.nativeElement).toHaveText('SIMPLE(A)');
async.done(); async.done();
}); });
})); }));
@ -106,9 +106,9 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
main.componentInstance.text = 'A'; main.debugElement.componentInstance.text = 'A';
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('SIMPLE(AEL)'); expect(main.debugElement.nativeElement).toHaveText('SIMPLE(AEL)');
async.done(); async.done();
}); });
})); }));
@ -120,7 +120,7 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText(''); expect(main.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
})); }));
@ -138,7 +138,7 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText('(A, BC)'); expect(main.debugElement.nativeElement).toHaveText('(A, BC)');
async.done(); async.done();
}); });
})); }));
@ -155,7 +155,7 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText('(, BAC)'); expect(main.debugElement.nativeElement).toHaveText('(, BAC)');
async.done(); async.done();
}); });
})); }));
@ -172,16 +172,17 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
var viewportDirectives = main.queryAll(By.directive(ManualViewportDirective)) var viewportDirectives =
.map(de => de.inject(ManualViewportDirective)); main.debugElement.queryAll(By.directive(ManualViewportDirective))
.map(de => de.inject(ManualViewportDirective));
expect(main.nativeElement).toHaveText('(, B)'); expect(main.debugElement.nativeElement).toHaveText('(, B)');
viewportDirectives.forEach(d => d.show()); viewportDirectives.forEach(d => d.show());
expect(main.nativeElement).toHaveText('(A1, B)'); expect(main.debugElement.nativeElement).toHaveText('(A1, B)');
viewportDirectives.forEach(d => d.hide()); viewportDirectives.forEach(d => d.hide());
expect(main.nativeElement).toHaveText('(, B)'); expect(main.debugElement.nativeElement).toHaveText('(, B)');
async.done(); async.done();
}); });
})); }));
@ -198,7 +199,7 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText('OUTER(SIMPLE(AB))'); expect(main.debugElement.nativeElement).toHaveText('OUTER(SIMPLE(AB))');
async.done(); async.done();
}); });
})); }));
@ -216,13 +217,14 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
var viewportDirective = main.query(By.directive(ManualViewportDirective)) var viewportDirective =
.inject(ManualViewportDirective); main.debugElement.query(By.directive(ManualViewportDirective))
.inject(ManualViewportDirective);
expect(main.nativeElement).toHaveText('OUTER(INNER(INNERINNER(,BC)))'); expect(main.debugElement.nativeElement).toHaveText('OUTER(INNER(INNERINNER(,BC)))');
viewportDirective.show(); viewportDirective.show();
expect(main.nativeElement).toHaveText('OUTER(INNER(INNERINNER(A,BC)))'); expect(main.debugElement.nativeElement).toHaveText('OUTER(INNER(INNERINNER(A,BC)))');
async.done(); async.done();
}); });
})); }));
@ -240,17 +242,18 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
var viewportDirective = main.query(By.directive(ManualViewportDirective)) var viewportDirective =
.inject(ManualViewportDirective); main.debugElement.query(By.directive(ManualViewportDirective))
.inject(ManualViewportDirective);
expect(main.nativeElement).toHaveText('(, BC)'); expect(main.debugElement.nativeElement).toHaveText('(, BC)');
viewportDirective.show(); viewportDirective.show();
expect(main.nativeElement).toHaveText('(A, BC)'); expect(main.debugElement.nativeElement).toHaveText('(A, BC)');
viewportDirective.hide(); viewportDirective.hide();
expect(main.nativeElement).toHaveText('(, BC)'); expect(main.debugElement.nativeElement).toHaveText('(, BC)');
async.done(); async.done();
}); });
})); }));
@ -267,11 +270,11 @@ export function main() {
{template: '<simple string-prop="text"></simple>', directives: [Simple]})) {template: '<simple string-prop="text"></simple>', directives: [Simple]}))
.overrideTemplate(Simple, '<ng-content></ng-content><p>P,</p>{{stringProp}}') .overrideTemplate(Simple, '<ng-content></ng-content><p>P,</p>{{stringProp}}')
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main: RootTestComponent) => {
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('P,text'); expect(main.debugElement.nativeElement).toHaveText('P,text');
async.done(); async.done();
}); });
@ -288,10 +291,10 @@ export function main() {
{template: '<simple string-prop="text"></simple>', directives: [Simple]})) {template: '<simple string-prop="text"></simple>', directives: [Simple]}))
.overrideTemplate(Simple, '<style></style><p>P,</p>{{stringProp}}') .overrideTemplate(Simple, '<style></style><p>P,</p>{{stringProp}}')
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main: RootTestComponent) => {
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('P,text'); expect(main.debugElement.nativeElement).toHaveText('P,text');
async.done(); async.done();
}); });
})); }));
@ -309,14 +312,14 @@ export function main() {
.then((main) => { .then((main) => {
var sourceDirective: ManualViewportDirective = var sourceDirective: ManualViewportDirective =
main.query(By.directive(ManualViewportDirective)) main.debugElement.query(By.directive(ManualViewportDirective))
.inject(ManualViewportDirective); .inject(ManualViewportDirective);
var projectDirective: ProjectDirective = var projectDirective: ProjectDirective =
main.query(By.directive(ProjectDirective)).inject(ProjectDirective); main.debugElement.query(By.directive(ProjectDirective)).inject(ProjectDirective);
expect(main.nativeElement).toHaveText('START()END'); expect(main.debugElement.nativeElement).toHaveText('START()END');
projectDirective.show(sourceDirective.templateRef); projectDirective.show(sourceDirective.templateRef);
expect(main.nativeElement).toHaveText('START(A)END'); expect(main.debugElement.nativeElement).toHaveText('START(A)END');
async.done(); async.done();
}); });
})); }));
@ -332,14 +335,14 @@ export function main() {
.then((main) => { .then((main) => {
var sourceDirective: ManualViewportDirective = var sourceDirective: ManualViewportDirective =
main.query(By.directive(ManualViewportDirective)) main.debugElement.query(By.directive(ManualViewportDirective))
.inject(ManualViewportDirective); .inject(ManualViewportDirective);
var projectDirective: ProjectDirective = var projectDirective: ProjectDirective =
main.query(By.directive(ProjectDirective)).inject(ProjectDirective); main.debugElement.query(By.directive(ProjectDirective)).inject(ProjectDirective);
expect(main.nativeElement).toHaveText('SIMPLE()START()END'); expect(main.debugElement.nativeElement).toHaveText('SIMPLE()START()END');
projectDirective.show(sourceDirective.templateRef); projectDirective.show(sourceDirective.templateRef);
expect(main.nativeElement).toHaveText('SIMPLE()START(A)END'); expect(main.debugElement.nativeElement).toHaveText('SIMPLE()START(A)END');
async.done(); async.done();
}); });
})); }));
@ -360,19 +363,19 @@ export function main() {
.then((main) => { .then((main) => {
var sourceDirective: ManualViewportDirective = var sourceDirective: ManualViewportDirective =
main.query(By.directive(ManualViewportDirective)) main.debugElement.query(By.directive(ManualViewportDirective))
.inject(ManualViewportDirective); .inject(ManualViewportDirective);
var projectDirective: ProjectDirective = var projectDirective: ProjectDirective =
main.query(By.directive(ProjectDirective)).inject(ProjectDirective); main.debugElement.query(By.directive(ProjectDirective)).inject(ProjectDirective);
expect(main.nativeElement).toHaveText('(, B)START()END'); expect(main.debugElement.nativeElement).toHaveText('(, B)START()END');
projectDirective.show(sourceDirective.templateRef); projectDirective.show(sourceDirective.templateRef);
expect(main.nativeElement).toHaveText('(, B)START(A)END'); expect(main.debugElement.nativeElement).toHaveText('(, B)START(A)END');
// Stamping ng-content multiple times should not produce the content multiple // Stamping ng-content multiple times should not produce the content multiple
// times... // times...
projectDirective.show(sourceDirective.templateRef); projectDirective.show(sourceDirective.templateRef);
expect(main.nativeElement).toHaveText('(, B)START(A)END'); expect(main.debugElement.nativeElement).toHaveText('(, B)START(A)END');
async.done(); async.done();
}); });
})); }));
@ -390,12 +393,12 @@ export function main() {
main.detectChanges(); main.detectChanges();
var manualDirective: ManualViewportDirective = var manualDirective: ManualViewportDirective =
main.query(By.directive(ManualViewportDirective)) main.debugElement.query(By.directive(ManualViewportDirective))
.inject(ManualViewportDirective); .inject(ManualViewportDirective);
expect(main.nativeElement).toHaveText('TREE(0:)'); expect(main.debugElement.nativeElement).toHaveText('TREE(0:)');
manualDirective.show(); manualDirective.show();
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('TREE(0:TREE(1:))'); expect(main.debugElement.nativeElement).toHaveText('TREE(0:TREE(1:))');
async.done(); async.done();
}); });
})); }));
@ -412,7 +415,7 @@ export function main() {
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText('SIMPLE(A)'); expect(main.debugElement.nativeElement).toHaveText('SIMPLE(A)');
async.done(); async.done();
}); });
})); }));
@ -429,15 +432,17 @@ export function main() {
})) }))
.createAsync(MainComp) .createAsync(MainComp)
.then((main) => { .then((main) => {
expect(main.nativeElement).toHaveText('MAIN()'); expect(main.debugElement.nativeElement).toHaveText('MAIN()');
var viewportElement = main.componentViewChildren[0].componentViewChildren[0]; var viewportElement =
main.debugElement.componentViewChildren[0].componentViewChildren[0];
viewportElement.inject(ManualViewportDirective).show(); viewportElement.inject(ManualViewportDirective).show();
expect(main.nativeElement).toHaveText('MAIN(FIRST())'); expect(main.debugElement.nativeElement).toHaveText('MAIN(FIRST())');
viewportElement = main.componentViewChildren[0].componentViewChildren[1]; viewportElement =
main.debugElement.componentViewChildren[0].componentViewChildren[1];
viewportElement.inject(ManualViewportDirective).show(); viewportElement.inject(ManualViewportDirective).show();
expect(main.nativeElement).toHaveText('MAIN(FIRST(SECOND(a)))'); expect(main.debugElement.nativeElement).toHaveText('MAIN(FIRST(SECOND(a)))');
async.done(); async.done();
}); });

View File

@ -49,7 +49,8 @@ export function main() {
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|3|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('2|3|');
async.done(); async.done();
}); });
@ -67,7 +68,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|3|4|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('2|3|4|');
async.done(); async.done();
}); });
@ -83,7 +85,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|3|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('2|3|');
async.done(); async.done();
}); });
@ -101,11 +104,12 @@ export function main() {
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|'); expect(asNativeElements(view.debugElement.componentViewChildren)).toHaveText('2|');
view.componentInstance.shouldShow = true; view.debugElement.componentInstance.shouldShow = true;
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|3|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('2|3|');
async.done(); async.done();
}); });
@ -121,7 +125,7 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((rtc) => { .then((rtc) => {
rtc.componentInstance.shouldShow = true; rtc.debugElement.componentInstance.shouldShow = true;
rtc.detectChanges(); rtc.detectChanges();
rtc.destroy(); rtc.destroy();
@ -141,11 +145,13 @@ export function main() {
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|1d|2d|3d|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('2|1d|2d|3d|');
view.componentInstance.list = ['3d', '2d']; view.debugElement.componentInstance.list = ['3d', '2d'];
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('2|3d|2d|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('2|3d|2d|');
async.done(); async.done();
}); });
@ -160,7 +166,8 @@ export function main() {
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
var needsTpl: NeedsTpl = view.componentViewChildren[0].inject(NeedsTpl); var needsTpl: NeedsTpl =
view.debugElement.componentViewChildren[0].inject(NeedsTpl);
expect(needsTpl.query.first.hasLocal('light')).toBe(true); expect(needsTpl.query.first.hasLocal('light')).toBe(true);
expect(needsTpl.viewQuery.first.hasLocal('shadow')).toBe(true); expect(needsTpl.viewQuery.first.hasLocal('shadow')).toBe(true);
@ -181,7 +188,7 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q = view.componentViewChildren[0].getLocal("q"); var q = view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
q.query.onChange(() => { q.query.onChange(() => {
@ -190,7 +197,7 @@ export function main() {
async.done(); async.done();
}); });
view.componentInstance.shouldShow = true; view.debugElement.componentInstance.shouldShow = true;
view.detectChanges(); view.detectChanges();
}); });
})); }));
@ -206,8 +213,8 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q1 = view.componentViewChildren[0].getLocal("q1"); var q1 = view.debugElement.componentViewChildren[0].getLocal("q1");
var q2 = view.componentViewChildren[0].getLocal("q2"); var q2 = view.debugElement.componentViewChildren[0].getLocal("q2");
var firedQ2 = false; var firedQ2 = false;
@ -229,19 +236,19 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
view.componentInstance.shouldShow = true; view.debugElement.componentInstance.shouldShow = true;
view.detectChanges(); view.detectChanges();
var q: NeedsQuery = view.componentViewChildren[1].getLocal('q'); var q: NeedsQuery = view.debugElement.componentViewChildren[1].getLocal('q');
expect(q.query.length).toEqual(1); expect(q.query.length).toEqual(1);
view.componentInstance.shouldShow = false; view.debugElement.componentInstance.shouldShow = false;
view.detectChanges(); view.detectChanges();
view.componentInstance.shouldShow = true; view.debugElement.componentInstance.shouldShow = true;
view.detectChanges(); view.detectChanges();
var q2: NeedsQuery = view.componentViewChildren[1].getLocal('q'); var q2: NeedsQuery = view.debugElement.componentViewChildren[1].getLocal('q');
expect(q2.query.length).toEqual(1); expect(q2.query.length).toEqual(1);
@ -261,9 +268,9 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q = view.componentViewChildren[0].getLocal("q"); var q = view.debugElement.componentViewChildren[0].getLocal("q");
view.componentInstance.list = ['1d', '2d']; view.debugElement.componentInstance.list = ['1d', '2d'];
view.detectChanges(); view.detectChanges();
@ -284,7 +291,7 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q = view.componentViewChildren[0].getLocal("q"); var q = view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
expect(q.query.first.text).toEqual("one"); expect(q.query.first.text).toEqual("one");
@ -304,13 +311,13 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q = view.componentViewChildren[0].getLocal("q"); var q = view.debugElement.componentViewChildren[0].getLocal("q");
view.componentInstance.list = ['1d', '2d']; view.debugElement.componentInstance.list = ['1d', '2d'];
view.detectChanges(); view.detectChanges();
view.componentInstance.list = ['2d', '1d']; view.debugElement.componentInstance.list = ['2d', '1d'];
view.detectChanges(); view.detectChanges();
@ -331,9 +338,9 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q = view.componentViewChildren[0].getLocal("q"); var q = view.debugElement.componentViewChildren[0].getLocal("q");
view.componentInstance.list = ['1d', '2d']; view.debugElement.componentInstance.list = ['1d', '2d'];
view.detectChanges(); view.detectChanges();
@ -355,7 +362,8 @@ export function main() {
.then((view) => { .then((view) => {
view.detectChanges(); view.detectChanges();
expect(asNativeElements(view.componentViewChildren)).toHaveText('hello|world|'); expect(asNativeElements(view.debugElement.componentViewChildren))
.toHaveText('hello|world|');
async.done(); async.done();
}); });
@ -368,7 +376,8 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQueryByLabel = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQueryByLabel =
view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
expect(q.query.first.nativeElement).toHaveText("text"); expect(q.query.first.nativeElement).toHaveText("text");
@ -386,7 +395,7 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQuery = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQuery = view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
@ -403,7 +412,7 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQuery = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQuery = view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
@ -420,7 +429,7 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQueryIf = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQueryIf = view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
@ -443,7 +452,8 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQueryNestedIf = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQueryNestedIf =
view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
@ -468,7 +478,8 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQueryOrder = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQueryOrder =
view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
@ -491,7 +502,8 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQueryOrderWithParent = view.componentViewChildren[0].getLocal("q"); var q: NeedsViewQueryOrderWithParent =
view.debugElement.componentViewChildren[0].getLocal("q");
view.detectChanges(); view.detectChanges();
@ -514,7 +526,8 @@ export function main() {
tcb.overrideTemplate(MyComp, template) tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp) .createAsync(MyComp)
.then((view) => { .then((view) => {
var q: NeedsViewQueryOrder = view.componentViewChildren[0].getLocal('q'); var q: NeedsViewQueryOrder =
view.debugElement.componentViewChildren[0].getLocal('q');
// no significance to 50, just a reasonably large cycle. // no significance to 50, just a reasonably large cycle.
for (var i = 0; i < 50; i++) { for (var i = 0; i < 50; i++) {

View File

@ -124,17 +124,17 @@ export function main() {
describe('debug element', function() { describe('debug element', function() {
it('should list component child elements', it('should list component child elements',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp) tcb.createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
var childEls = rootTestComponent.children; var childEls = rootTestComponent.debugElement.children;
// The root is a lone component, and has no children in the light dom. // The root is a lone component, and has no children in the light dom.
expect(childEls.length).toEqual(0); expect(childEls.length).toEqual(0);
var rootCompChildren = rootTestComponent.componentViewChildren; var rootCompChildren = rootTestComponent.debugElement.componentViewChildren;
// The root component has 3 elements in its shadow view. // The root component has 3 elements in its shadow view.
expect(rootCompChildren.length).toEqual(3); expect(rootCompChildren.length).toEqual(3);
expect(DOM.hasClass(rootCompChildren[0].nativeElement, 'parent')).toBe(true); expect(DOM.hasClass(rootCompChildren[0].nativeElement, 'parent')).toBe(true);
@ -163,12 +163,12 @@ export function main() {
})); }));
it('should list child elements within viewports', it('should list child elements within viewports',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(UsingFor).then((rootTestComponent) => { tcb.createAsync(UsingFor).then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
var childEls = rootTestComponent.componentViewChildren; var childEls = rootTestComponent.debugElement.componentViewChildren;
// TODO should this count include the <template> element? // TODO should this count include the <template> element?
expect(childEls.length).toEqual(5); expect(childEls.length).toEqual(5);
@ -180,13 +180,13 @@ export function main() {
})); }));
it('should query child elements', it('should query child elements',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp) tcb.createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
var childTestEls = rootTestComponent.queryAll(By.directive(MessageDir)); var childTestEls = rootTestComponent.debugElement.queryAll(By.directive(MessageDir));
expect(childTestEls.length).toBe(4); expect(childTestEls.length).toBe(4);
expect(DOM.hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true); expect(DOM.hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true);
@ -198,13 +198,13 @@ export function main() {
})); }));
it('should query child elements in the light DOM', it('should query child elements in the light DOM',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp) tcb.createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
var parentEl = rootTestComponent.componentViewChildren[0]; var parentEl = rootTestComponent.debugElement.componentViewChildren[0];
var childTestEls = parentEl.queryAll(By.directive(MessageDir), Scope.light); var childTestEls = parentEl.queryAll(By.directive(MessageDir), Scope.light);
@ -216,13 +216,14 @@ export function main() {
})); }));
it('should query child elements in the current component view DOM', it('should query child elements in the current component view DOM',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp) tcb.createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
var childTestEls = rootTestComponent.queryAll(By.directive(MessageDir), Scope.view); var childTestEls =
rootTestComponent.debugElement.queryAll(By.directive(MessageDir), Scope.view);
expect(childTestEls.length).toBe(2); expect(childTestEls.length).toBe(2);
expect(DOM.hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true); expect(DOM.hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true);
@ -233,13 +234,13 @@ export function main() {
})); }));
it('should allow injecting from the element injector', it('should allow injecting from the element injector',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ParentComp) tcb.createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.componentViewChildren[0].inject(Logger).log) expect(rootTestComponent.debugElement.componentViewChildren[0].inject(Logger).log)
.toEqual(['parent', 'nestedparent', 'child', 'nestedchild']); .toEqual(['parent', 'nestedparent', 'child', 'nestedchild']);
async.done(); async.done();
@ -247,20 +248,22 @@ export function main() {
})); }));
it('should trigger event handlers', it('should trigger event handlers',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(EventsComp) tcb.createAsync(EventsComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.componentInstance.clicked).toBe(false); expect(rootTestComponent.debugElement.componentInstance.clicked).toBe(false);
expect(rootTestComponent.componentInstance.customed).toBe(false); expect(rootTestComponent.debugElement.componentInstance.customed).toBe(false);
rootTestComponent.componentViewChildren[0].triggerEventHandler('click', {}); rootTestComponent.debugElement.componentViewChildren[0].triggerEventHandler(
expect(rootTestComponent.componentInstance.clicked).toBe(true); 'click', <Event>{});
expect(rootTestComponent.debugElement.componentInstance.clicked).toBe(true);
rootTestComponent.componentViewChildren[1].triggerEventHandler('myevent', {}); rootTestComponent.debugElement.componentViewChildren[1].triggerEventHandler(
expect(rootTestComponent.componentInstance.customed).toBe(true); 'myevent', <Event>{});
expect(rootTestComponent.debugElement.componentInstance.customed).toBe(true);
async.done(); async.done();
}); });

View File

@ -31,11 +31,12 @@ export function main() {
beforeEachBindings(() => [bind(APP_VIEW_POOL_CAPACITY).toValue(0)]); beforeEachBindings(() => [bind(APP_VIEW_POOL_CAPACITY).toValue(0)]);
it('should return a TestElement from a dom element', it('should return a TestElement from a dom element',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '<div some-dir></div>') tcb.overrideTemplate(MyComp, '<div some-dir></div>')
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
expect(inspectNativeElement(rootTestComponent.nativeElement).componentInstance) expect(inspectNativeElement(rootTestComponent.debugElement.nativeElement)
.componentInstance)
.toBeAnInstanceOf(MyComp); .toBeAnInstanceOf(MyComp);
async.done(); async.done();
@ -43,12 +44,13 @@ export function main() {
})); }));
it('should clean up whent the view is destroyed', it('should clean up whent the view is destroyed',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '') tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.destroy(); rootTestComponent.destroy();
expect(inspectNativeElement(rootTestComponent.nativeElement)).toBe(null); expect(inspectNativeElement(rootTestComponent.debugElement.nativeElement))
.toBe(null);
async.done(); async.done();
}); });
@ -57,11 +59,12 @@ export function main() {
if (!IS_DART) { if (!IS_DART) {
it('should provide a global function to inspect elements', it('should provide a global function to inspect elements',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '') tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp) .createAsync(MyComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
expect(global['ng']['probe'](rootTestComponent.nativeElement).componentInstance) expect(global['ng']['probe'](rootTestComponent.debugElement.nativeElement)
.componentInstance)
.toBeAnInstanceOf(MyComp); .toBeAnInstanceOf(MyComp);
async.done(); async.done();

View File

@ -1,4 +1,5 @@
import { import {
RootTestComponent,
AsyncTestCompleter, AsyncTestCompleter,
TestComponentBuilder, TestComponentBuilder,
beforeEach, beforeEach,
@ -18,9 +19,10 @@ import {Component, View, NgFor, bind} from 'angular2/angular2';
import {NgClass} from 'angular2/src/core/directives/ng_class'; import {NgClass} from 'angular2/src/core/directives/ng_class';
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool'; import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
function detectChangesAndCheck(rootTC, classes: string, elIndex: number = 0) { function detectChangesAndCheck(rootTC: RootTestComponent, classes: string, elIndex: number = 0) {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren[elIndex].nativeElement.className).toEqual(classes); expect(rootTC.debugElement.componentViewChildren[elIndex].nativeElement.className)
.toEqual(classes);
} }
export function main() { export function main() {
@ -35,9 +37,9 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.items = [['0']]; rootTC.debugElement.componentInstance.items = [['0']];
rootTC.detectChanges(); rootTC.detectChanges();
rootTC.componentInstance.items = [['1']]; rootTC.debugElement.componentInstance.items = [['1']];
detectChangesAndCheck(rootTC, 'ng-binding 1', 1); detectChangesAndCheck(rootTC, 'ng-binding 1', 1);
@ -83,7 +85,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
rootTC.componentInstance.condition = false; rootTC.debugElement.componentInstance.condition = false;
detectChangesAndCheck(rootTC, 'ng-binding bar'); detectChangesAndCheck(rootTC, 'ng-binding bar');
async.done(); async.done();
@ -99,13 +101,13 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'ng-binding foo bar'); detectChangesAndCheck(rootTC, 'ng-binding foo bar');
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'baz', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'baz', true);
detectChangesAndCheck(rootTC, 'ng-binding foo bar baz'); detectChangesAndCheck(rootTC, 'ng-binding foo bar baz');
StringMapWrapper.delete(rootTC.componentInstance.objExpr, 'bar'); StringMapWrapper.delete(rootTC.debugElement.componentInstance.objExpr, 'bar');
detectChangesAndCheck(rootTC, 'ng-binding foo baz'); detectChangesAndCheck(rootTC, 'ng-binding foo baz');
async.done(); async.done();
@ -121,10 +123,10 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
rootTC.componentInstance.objExpr = {foo: true, bar: true}; rootTC.debugElement.componentInstance.objExpr = {foo: true, bar: true};
detectChangesAndCheck(rootTC, 'ng-binding foo bar'); detectChangesAndCheck(rootTC, 'ng-binding foo bar');
rootTC.componentInstance.objExpr = {baz: true}; rootTC.debugElement.componentInstance.objExpr = {baz: true};
detectChangesAndCheck(rootTC, 'ng-binding baz'); detectChangesAndCheck(rootTC, 'ng-binding baz');
async.done(); async.done();
@ -140,10 +142,10 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
rootTC.componentInstance.objExpr = null; rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, 'ng-binding'); detectChangesAndCheck(rootTC, 'ng-binding');
rootTC.componentInstance.objExpr = {'foo': false, 'bar': true}; rootTC.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true};
detectChangesAndCheck(rootTC, 'ng-binding bar'); detectChangesAndCheck(rootTC, 'ng-binding bar');
async.done(); async.done();
@ -172,7 +174,7 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
var arrExpr: string[] = rootTC.componentInstance.arrExpr; var arrExpr: string[] = rootTC.debugElement.componentInstance.arrExpr;
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
arrExpr.push('bar'); arrExpr.push('bar');
@ -181,7 +183,7 @@ export function main() {
arrExpr[1] = 'baz'; arrExpr[1] = 'baz';
detectChangesAndCheck(rootTC, 'ng-binding foo baz'); detectChangesAndCheck(rootTC, 'ng-binding foo baz');
ListWrapper.remove(rootTC.componentInstance.arrExpr, 'baz'); ListWrapper.remove(rootTC.debugElement.componentInstance.arrExpr, 'baz');
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
async.done(); async.done();
@ -197,7 +199,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
rootTC.componentInstance.arrExpr = ['bar']; rootTC.debugElement.componentInstance.arrExpr = ['bar'];
detectChangesAndCheck(rootTC, 'ng-binding bar'); detectChangesAndCheck(rootTC, 'ng-binding bar');
async.done(); async.done();
@ -213,7 +215,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo ng-binding'); detectChangesAndCheck(rootTC, 'foo ng-binding');
rootTC.componentInstance.arrExpr = ['bar']; rootTC.debugElement.componentInstance.arrExpr = ['bar'];
detectChangesAndCheck(rootTC, 'ng-binding foo bar'); detectChangesAndCheck(rootTC, 'ng-binding foo bar');
async.done(); async.done();
@ -244,11 +246,11 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
rootTC.componentInstance.strExpr = 'foo bar'; rootTC.debugElement.componentInstance.strExpr = 'foo bar';
detectChangesAndCheck(rootTC, 'ng-binding foo bar'); detectChangesAndCheck(rootTC, 'ng-binding foo bar');
rootTC.componentInstance.strExpr = 'baz'; rootTC.debugElement.componentInstance.strExpr = 'baz';
detectChangesAndCheck(rootTC, 'ng-binding baz'); detectChangesAndCheck(rootTC, 'ng-binding baz');
async.done(); async.done();
@ -264,7 +266,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
rootTC.componentInstance.strExpr = null; rootTC.debugElement.componentInstance.strExpr = null;
detectChangesAndCheck(rootTC, 'ng-binding'); detectChangesAndCheck(rootTC, 'ng-binding');
async.done(); async.done();
@ -280,7 +282,7 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'foo ng-binding'); detectChangesAndCheck(rootTC, 'foo ng-binding');
rootTC.componentInstance.strExpr = null; rootTC.debugElement.componentInstance.strExpr = null;
detectChangesAndCheck(rootTC, 'ng-binding foo'); detectChangesAndCheck(rootTC, 'ng-binding foo');
async.done(); async.done();
@ -298,13 +300,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'init foo ng-binding bar'); detectChangesAndCheck(rootTC, 'init foo ng-binding bar');
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, 'init ng-binding bar'); detectChangesAndCheck(rootTC, 'init ng-binding bar');
rootTC.componentInstance.objExpr = null; rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, 'init ng-binding foo'); detectChangesAndCheck(rootTC, 'init ng-binding foo');
async.done(); async.done();
@ -318,13 +320,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init foo bar`); detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init foo bar`);
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init bar`); detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init bar`);
rootTC.componentInstance.objExpr = null; rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init foo`); detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init foo`);
async.done(); async.done();
@ -338,13 +340,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, `init ng-binding foo bar`); detectChangesAndCheck(rootTC, `init ng-binding foo bar`);
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, `init ng-binding bar`); detectChangesAndCheck(rootTC, `init ng-binding bar`);
rootTC.componentInstance.objExpr = null; rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, `init ng-binding foo`); detectChangesAndCheck(rootTC, `init ng-binding foo`);
async.done(); async.done();
@ -361,13 +363,13 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'init foo ng-binding baz'); detectChangesAndCheck(rootTC, 'init foo ng-binding baz');
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'init foo ng-binding baz bar'); detectChangesAndCheck(rootTC, 'init foo ng-binding baz bar');
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'foo', false);
detectChangesAndCheck(rootTC, 'init ng-binding baz bar'); detectChangesAndCheck(rootTC, 'init ng-binding baz bar');
rootTC.componentInstance.condition = false; rootTC.debugElement.componentInstance.condition = false;
detectChangesAndCheck(rootTC, 'init ng-binding bar'); detectChangesAndCheck(rootTC, 'init ng-binding bar');
async.done(); async.done();
@ -383,13 +385,13 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
detectChangesAndCheck(rootTC, 'init ng-binding foo'); detectChangesAndCheck(rootTC, 'init ng-binding foo');
StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); StringMapWrapper.set(rootTC.debugElement.componentInstance.objExpr, 'bar', true);
detectChangesAndCheck(rootTC, 'init ng-binding foo bar'); detectChangesAndCheck(rootTC, 'init ng-binding foo bar');
rootTC.componentInstance.strExpr = 'baz'; rootTC.debugElement.componentInstance.strExpr = 'baz';
detectChangesAndCheck(rootTC, 'init ng-binding bar baz foo'); detectChangesAndCheck(rootTC, 'init ng-binding bar baz foo');
rootTC.componentInstance.objExpr = null; rootTC.debugElement.componentInstance.objExpr = null;
detectChangesAndCheck(rootTC, 'init ng-binding baz'); detectChangesAndCheck(rootTC, 'init ng-binding baz');
async.done(); async.done();

View File

@ -31,7 +31,7 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('1;2;'); expect(rootTC.debugElement.nativeElement).toHaveText('1;2;');
async.done(); async.done();
}); });
})); }));
@ -43,10 +43,10 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
(<number[]>rootTC.componentInstance.items).push(3); (<number[]>rootTC.debugElement.componentInstance.items).push(3);
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('1;2;3;'); expect(rootTC.debugElement.nativeElement).toHaveText('1;2;3;');
async.done(); async.done();
}); });
})); }));
@ -58,10 +58,10 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
ListWrapper.removeAt(rootTC.componentInstance.items, 1); ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 1);
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('1;'); expect(rootTC.debugElement.nativeElement).toHaveText('1;');
async.done(); async.done();
}); });
})); }));
@ -73,11 +73,11 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
ListWrapper.removeAt(rootTC.componentInstance.items, 0); ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 0);
(<number[]>rootTC.componentInstance.items).push(1); (<number[]>rootTC.debugElement.componentInstance.items).push(1);
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('2;1;'); expect(rootTC.debugElement.nativeElement).toHaveText('2;1;');
async.done(); async.done();
}); });
})); }));
@ -87,13 +87,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, TEMPLATE) tcb.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.items = [0, 1, 2, 3, 4, 5]; rootTC.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5];
rootTC.detectChanges(); rootTC.detectChanges();
rootTC.componentInstance.items = [6, 2, 7, 0, 4, 8]; rootTC.debugElement.componentInstance.items = [6, 2, 7, 0, 4, 8];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('6;2;7;0;4;8;'); expect(rootTC.debugElement.nativeElement).toHaveText('6;2;7;0;4;8;');
async.done(); async.done();
}); });
})); }));
@ -107,22 +107,22 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
// INIT // INIT
rootTC.componentInstance.items = [{'name': 'misko'}, {'name': 'shyam'}]; rootTC.debugElement.componentInstance.items = [{'name': 'misko'}, {'name': 'shyam'}];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('misko;shyam;'); expect(rootTC.debugElement.nativeElement).toHaveText('misko;shyam;');
// GROW // GROW
(<any[]>rootTC.componentInstance.items).push({'name': 'adam'}); (<any[]>rootTC.debugElement.componentInstance.items).push({'name': 'adam'});
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('misko;shyam;adam;'); expect(rootTC.debugElement.nativeElement).toHaveText('misko;shyam;adam;');
// SHRINK // SHRINK
ListWrapper.removeAt(rootTC.componentInstance.items, 2); ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 2);
ListWrapper.removeAt(rootTC.componentInstance.items, 0); ListWrapper.removeAt(rootTC.debugElement.componentInstance.items, 0);
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('shyam;'); expect(rootTC.debugElement.nativeElement).toHaveText('shyam;');
async.done(); async.done();
}); });
})); }));
@ -134,7 +134,7 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(''); expect(rootTC.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
})); }));
@ -145,15 +145,15 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('1;2;'); expect(rootTC.debugElement.nativeElement).toHaveText('1;2;');
rootTC.componentInstance.items = null; rootTC.debugElement.componentInstance.items = null;
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(''); expect(rootTC.debugElement.nativeElement).toHaveText('');
rootTC.componentInstance.items = [1, 2, 3]; rootTC.debugElement.componentInstance.items = [1, 2, 3];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('1;2;3;'); expect(rootTC.debugElement.nativeElement).toHaveText('1;2;3;');
async.done(); async.done();
}); });
})); }));
@ -164,9 +164,9 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('1;2;'); expect(rootTC.debugElement.nativeElement).toHaveText('1;2;');
rootTC.componentInstance.items = 'whaaa'; rootTC.debugElement.componentInstance.items = 'whaaa';
expect(() => rootTC.detectChanges()).toThrowError(); expect(() => rootTC.detectChanges()).toThrowError();
async.done(); async.done();
}); });
@ -178,9 +178,9 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
var a = new Foo(); var a = new Foo();
rootTC.componentInstance.items = [a, a]; rootTC.debugElement.componentInstance.items = [a, a];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('foo;foo;'); expect(rootTC.debugElement.nativeElement).toHaveText('foo;foo;');
async.done(); async.done();
}); });
})); }));
@ -198,15 +198,15 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.items = [['a', 'b'], ['c']]; rootTC.debugElement.componentInstance.items = [['a', 'b'], ['c']];
rootTC.detectChanges(); rootTC.detectChanges();
rootTC.detectChanges(); rootTC.detectChanges();
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('a-2;b-2;|c-1;|'); expect(rootTC.debugElement.nativeElement).toHaveText('a-2;b-2;|c-1;|');
rootTC.componentInstance.items = [['e'], ['f', 'g']]; rootTC.debugElement.componentInstance.items = [['e'], ['f', 'g']];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('e-1;|f-2;g-2;|'); expect(rootTC.debugElement.nativeElement).toHaveText('e-1;|f-2;g-2;|');
async.done(); async.done();
}); });
@ -222,13 +222,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.items = [['a', 'b'], ['c']]; rootTC.debugElement.componentInstance.items = [['a', 'b'], ['c']];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('a-2;b-2;c-1;'); expect(rootTC.debugElement.nativeElement).toHaveText('a-2;b-2;c-1;');
rootTC.componentInstance.items = [['e'], ['f', 'g']]; rootTC.debugElement.componentInstance.items = [['e'], ['f', 'g']];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('e-1;f-2;g-2;'); expect(rootTC.debugElement.nativeElement).toHaveText('e-1;f-2;g-2;');
async.done(); async.done();
}); });
})); }));
@ -241,13 +241,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; rootTC.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('0123456789'); expect(rootTC.debugElement.nativeElement).toHaveText('0123456789');
rootTC.componentInstance.items = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0]; rootTC.debugElement.componentInstance.items = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('0123456789'); expect(rootTC.debugElement.nativeElement).toHaveText('0123456789');
async.done(); async.done();
}); });
})); }));
@ -260,13 +260,13 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.items = [0, 1, 2]; rootTC.debugElement.componentInstance.items = [0, 1, 2];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('falsefalsetrue'); expect(rootTC.debugElement.nativeElement).toHaveText('falsefalsetrue');
rootTC.componentInstance.items = [2, 1]; rootTC.debugElement.componentInstance.items = [2, 1];
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('falsetrue'); expect(rootTC.debugElement.nativeElement).toHaveText('falsetrue');
async.done(); async.done();
}); });
})); }));

View File

@ -28,8 +28,9 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
async.done(); async.done();
}); });
})); }));
@ -43,8 +44,9 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello2'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello2');
async.done(); async.done();
}); });
})); }));
@ -56,20 +58,23 @@ export function main() {
tcb.overrideTemplate(TestComponent, html) tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.booleanCondition = false; rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText(''); .toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
rootTC.componentInstance.booleanCondition = true; rootTC.debugElement.componentInstance.booleanCondition = true;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
rootTC.componentInstance.booleanCondition = false; rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText(''); .toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
@ -83,30 +88,35 @@ export function main() {
tcb.overrideTemplate(TestComponent, html) tcb.overrideTemplate(TestComponent, html)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.booleanCondition = false; rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText(''); .toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
rootTC.componentInstance.booleanCondition = true; rootTC.debugElement.componentInstance.booleanCondition = true;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
rootTC.componentInstance.nestedBooleanCondition = false; rootTC.debugElement.componentInstance.nestedBooleanCondition = false;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText(''); .toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
rootTC.componentInstance.nestedBooleanCondition = true; rootTC.debugElement.componentInstance.nestedBooleanCondition = true;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
rootTC.componentInstance.booleanCondition = false; rootTC.debugElement.componentInstance.booleanCondition = false;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText(''); .toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
@ -125,20 +135,23 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(3); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(DOM.getText(rootTC.nativeElement)) .toEqual(3);
expect(DOM.getText(rootTC.debugElement.nativeElement))
.toEqual('helloNumberhelloStringhelloFunction'); .toEqual('helloNumberhelloStringhelloFunction');
rootTC.componentInstance.numberCondition = 0; rootTC.debugElement.componentInstance.numberCondition = 0;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('helloString'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('helloString');
rootTC.componentInstance.numberCondition = 1; rootTC.debugElement.componentInstance.numberCondition = 1;
rootTC.componentInstance.stringCondition = "bar"; rootTC.debugElement.componentInstance.stringCondition = "bar";
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('helloNumber'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('helloNumber');
async.done(); async.done();
}); });
})); }));
@ -153,13 +166,15 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
rootTC.componentInstance.numberCondition = 2; rootTC.debugElement.componentInstance.numberCondition = 2;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(1); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText('hello'); .toEqual(1);
expect(rootTC.debugElement.nativeElement).toHaveText('hello');
async.done(); async.done();
}); });
@ -173,11 +188,13 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
DOM.addClass(DOM.querySelector(rootTC.nativeElement, 'copy-me'), "foo"); DOM.addClass(DOM.querySelector(rootTC.debugElement.nativeElement, 'copy-me'),
"foo");
rootTC.componentInstance.numberCondition = 2; rootTC.debugElement.componentInstance.numberCondition = 2;
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.hasClass(DOM.querySelector(rootTC.nativeElement, 'copy-me'), "foo")) expect(DOM.hasClass(
DOM.querySelector(rootTC.debugElement.nativeElement, 'copy-me'), "foo"))
.toBe(true); .toBe(true);
async.done(); async.done();
@ -194,8 +211,9 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
expect(() => rootTC.detectChanges()).toThrowError(); expect(() => rootTC.detectChanges()).toThrowError();
expect(DOM.querySelectorAll(rootTC.nativeElement, 'copy-me').length).toEqual(0); expect(DOM.querySelectorAll(rootTC.debugElement.nativeElement, 'copy-me').length)
expect(rootTC.nativeElement).toHaveText(''); .toEqual(0);
expect(rootTC.debugElement.nativeElement).toHaveText('');
async.done(); async.done();
}); });
})); }));

View File

@ -32,7 +32,8 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px'); .toEqual('40px');
async.done(); async.done();
@ -48,15 +49,17 @@ export function main() {
.then((rootTC) => { .then((rootTC) => {
var expr: Map<string, any>; var expr: Map<string, any>;
rootTC.componentInstance.expr = {'max-width': '40px'}; rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px'); .toEqual('40px');
expr = rootTC.componentInstance.expr; expr = rootTC.debugElement.componentInstance.expr;
expr['max-width'] = '30%'; expr['max-width'] = '30%';
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('30%'); .toEqual('30%');
async.done(); async.done();
@ -70,14 +73,16 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.expr = {'max-width': '40px'}; rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px'); .toEqual('40px');
StringMapWrapper.delete(rootTC.componentInstance.expr, 'max-width'); StringMapWrapper.delete(rootTC.debugElement.componentInstance.expr, 'max-width');
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual(''); .toEqual('');
async.done(); async.done();
@ -91,18 +96,22 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.expr = {'max-width': '40px'}; rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px'); .toEqual('40px');
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px'); .toEqual('12px');
StringMapWrapper.delete(rootTC.componentInstance.expr, 'max-width'); StringMapWrapper.delete(rootTC.debugElement.componentInstance.expr, 'max-width');
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual(''); .toEqual('');
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px'); .toEqual('12px');
async.done(); async.done();
@ -116,19 +125,23 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.expr = {'max-width': '40px'}; rootTC.debugElement.componentInstance.expr = {'max-width': '40px'};
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual('40px'); .toEqual('40px');
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px'); .toEqual('12px');
StringMapWrapper.delete(rootTC.componentInstance.expr, 'max-width'); StringMapWrapper.delete(rootTC.debugElement.componentInstance.expr, 'max-width');
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'font-size'))
.toEqual('12px'); .toEqual('12px');
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width')) expect(DOM.getStyle(rootTC.debugElement.componentViewChildren[0].nativeElement,
'max-width'))
.toEqual(''); .toEqual('');
async.done(); async.done();

View File

@ -31,15 +31,15 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(''); expect(rootTC.debugElement.nativeElement).toHaveText('');
rootTC.componentInstance.switchValue = 'a'; rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when a'); expect(rootTC.debugElement.nativeElement).toHaveText('when a');
rootTC.componentInstance.switchValue = 'b'; rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when b'); expect(rootTC.debugElement.nativeElement).toHaveText('when b');
async.done(); async.done();
}); });
@ -57,15 +57,15 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when default'); expect(rootTC.debugElement.nativeElement).toHaveText('when default');
rootTC.componentInstance.switchValue = 'a'; rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when a'); expect(rootTC.debugElement.nativeElement).toHaveText('when a');
rootTC.componentInstance.switchValue = 'b'; rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when default'); expect(rootTC.debugElement.nativeElement).toHaveText('when default');
async.done(); async.done();
}); });
@ -87,15 +87,16 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when default1;when default2;'); expect(rootTC.debugElement.nativeElement)
.toHaveText('when default1;when default2;');
rootTC.componentInstance.switchValue = 'a'; rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when a1;when a2;'); expect(rootTC.debugElement.nativeElement).toHaveText('when a1;when a2;');
rootTC.componentInstance.switchValue = 'b'; rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when b1;when b2;'); expect(rootTC.debugElement.nativeElement).toHaveText('when b1;when b2;');
async.done(); async.done();
}); });
@ -115,27 +116,27 @@ export function main() {
tcb.overrideTemplate(TestComponent, template) tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.componentInstance.when1 = 'a'; rootTC.debugElement.componentInstance.when1 = 'a';
rootTC.componentInstance.when2 = 'b'; rootTC.debugElement.componentInstance.when2 = 'b';
rootTC.componentInstance.switchValue = 'a'; rootTC.debugElement.componentInstance.switchValue = 'a';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when 1;'); expect(rootTC.debugElement.nativeElement).toHaveText('when 1;');
rootTC.componentInstance.switchValue = 'b'; rootTC.debugElement.componentInstance.switchValue = 'b';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when 2;'); expect(rootTC.debugElement.nativeElement).toHaveText('when 2;');
rootTC.componentInstance.switchValue = 'c'; rootTC.debugElement.componentInstance.switchValue = 'c';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when default;'); expect(rootTC.debugElement.nativeElement).toHaveText('when default;');
rootTC.componentInstance.when1 = 'c'; rootTC.debugElement.componentInstance.when1 = 'c';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when 1;'); expect(rootTC.debugElement.nativeElement).toHaveText('when 1;');
rootTC.componentInstance.when1 = 'd'; rootTC.debugElement.componentInstance.when1 = 'd';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('when default;'); expect(rootTC.debugElement.nativeElement).toHaveText('when default;');
async.done(); async.done();
}); });

View File

@ -24,7 +24,7 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('foo{{text}}'); expect(rootTC.debugElement.nativeElement).toHaveText('foo{{text}}');
async.done(); async.done();
}); });
})); }));
@ -39,7 +39,7 @@ export function main() {
// We must use DOM.querySelector instead of rootTC.query here // We must use DOM.querySelector instead of rootTC.query here
// since the elements inside are not compiled. // since the elements inside are not compiled.
var span = DOM.querySelector(rootTC.nativeElement, '#child'); var span = DOM.querySelector(rootTC.debugElement.nativeElement, '#child');
expect(DOM.hasClass(span, 'compiled')).toBeFalsy(); expect(DOM.hasClass(span, 'compiled')).toBeFalsy();
async.done(); async.done();
}); });
@ -52,7 +52,7 @@ export function main() {
.createAsync(TestComponent) .createAsync(TestComponent)
.then((rootTC) => { .then((rootTC) => {
rootTC.detectChanges(); rootTC.detectChanges();
var span = DOM.querySelector(rootTC.nativeElement, '#child'); var span = DOM.querySelector(rootTC.debugElement.nativeElement, '#child');
expect(DOM.hasClass(span, 'compiled')).toBeTruthy(); expect(DOM.hasClass(span, 'compiled')).toBeTruthy();
async.done(); async.done();
}); });

View File

@ -1,5 +1,6 @@
import {Component, Directive, View} from 'angular2/angular2'; import {Component, Directive, View} from 'angular2/angular2';
import { import {
RootTestComponent,
afterEach, afterEach,
AsyncTestCompleter, AsyncTestCompleter,
TestComponentBuilder, TestComponentBuilder,
@ -40,10 +41,11 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"login": new Control("loginValue")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"login": new Control("loginValue")});
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("loginValue"); expect(input.nativeElement.value).toEqual("loginValue");
async.done(); async.done();
}); });
@ -58,9 +60,9 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
input.nativeElement.value = "updatedValue"; input.nativeElement.value = "updatedValue";
dispatchEvent(input.nativeElement, "change"); dispatchEvent(input.nativeElement, "change");
@ -76,21 +78,21 @@ export function main() {
var t = var t =
`<div><form [ng-form-model]="form" (ng-submit)="name='updated'"></form><span>{{name}}</span></div>`; `<div><form [ng-form-model]="form" (ng-submit)="name='updated'"></form><span>{{name}}</span></div>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; }); tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.form = new ControlGroup({}); rootTC.debugElement.componentInstance.form = new ControlGroup({});
rootTC.componentInstance.name = 'old'; rootTC.debugElement.componentInstance.name = 'old';
tick(); tick();
var form = rootTC.query(By.css("form")); var form = rootTC.debugElement.query(By.css("form"));
dispatchEvent(form.nativeElement, "submit"); dispatchEvent(form.nativeElement, "submit");
tick(); tick();
expect(rootTC.componentInstance.name).toEqual('updated'); expect(rootTC.debugElement.componentInstance.name).toEqual('updated');
}))); })));
it("should work with single controls", it("should work with single controls",
@ -100,10 +102,10 @@ export function main() {
var t = `<div><input type="text" [ng-form-control]="form"></div>`; var t = `<div><input type="text" [ng-form-control]="form"></div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = control; rootTC.debugElement.componentInstance.form = control;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("loginValue"); expect(input.nativeElement.value).toEqual("loginValue");
input.nativeElement.value = "updatedValue"; input.nativeElement.value = "updatedValue";
@ -121,13 +123,15 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"login": new Control("oldValue")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"login": new Control("oldValue")});
rootTC.detectChanges(); rootTC.detectChanges();
rootTC.componentInstance.form = new ControlGroup({"login": new Control("newValue")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"login": new Control("newValue")});
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("newValue"); expect(input.nativeElement.value).toEqual("newValue");
async.done(); async.done();
}); });
@ -143,14 +147,14 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
login.updateValue("newValue"); login.updateValue("newValue");
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("newValue"); expect(input.nativeElement.value).toEqual("newValue");
async.done(); async.done();
}); });
@ -166,10 +170,10 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var loginEl = rootTC.query(By.css("input")); var loginEl = rootTC.debugElement.query(By.css("input"));
expect(login.touched).toBe(false); expect(login.touched).toBe(false);
dispatchEvent(loginEl.nativeElement, "blur"); dispatchEvent(loginEl.nativeElement, "blur");
@ -188,16 +192,17 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"text": new Control("old")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"text": new Control("old")});
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("old"); expect(input.nativeElement.value).toEqual("old");
input.nativeElement.value = "new"; input.nativeElement.value = "new";
dispatchEvent(input.nativeElement, "input"); dispatchEvent(input.nativeElement, "input");
expect(rootTC.componentInstance.form.value).toEqual({"text": "new"}); expect(rootTC.debugElement.componentInstance.form.value).toEqual({"text": "new"});
async.done(); async.done();
}); });
})); }));
@ -209,15 +214,16 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"text": new Control("old")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"text": new Control("old")});
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("old"); expect(input.nativeElement.value).toEqual("old");
input.nativeElement.value = "new"; input.nativeElement.value = "new";
dispatchEvent(input.nativeElement, "input"); dispatchEvent(input.nativeElement, "input");
expect(rootTC.componentInstance.form.value).toEqual({"text": "new"}); expect(rootTC.debugElement.componentInstance.form.value).toEqual({"text": "new"});
async.done(); async.done();
}); });
})); }));
@ -229,16 +235,17 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"text": new Control('old')}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"text": new Control('old')});
rootTC.detectChanges(); rootTC.detectChanges();
var textarea = rootTC.query(By.css("textarea")); var textarea = rootTC.debugElement.query(By.css("textarea"));
expect(textarea.nativeElement.value).toEqual("old"); expect(textarea.nativeElement.value).toEqual("old");
textarea.nativeElement.value = "new"; textarea.nativeElement.value = "new";
dispatchEvent(textarea.nativeElement, "input"); dispatchEvent(textarea.nativeElement, "input");
expect(rootTC.componentInstance.form.value).toEqual({"text": 'new'}); expect(rootTC.debugElement.componentInstance.form.value).toEqual({"text": 'new'});
async.done(); async.done();
}); });
})); }));
@ -250,16 +257,17 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"checkbox": new Control(true)}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"checkbox": new Control(true)});
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.checked).toBe(true); expect(input.nativeElement.checked).toBe(true);
input.nativeElement.checked = false; input.nativeElement.checked = false;
dispatchEvent(input.nativeElement, "change"); dispatchEvent(input.nativeElement, "change");
expect(rootTC.componentInstance.form.value).toEqual({"checkbox": false}); expect(rootTC.debugElement.componentInstance.form.value).toEqual({"checkbox": false});
async.done(); async.done();
}); });
})); }));
@ -274,18 +282,19 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"city": new Control("SF")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"city": new Control("SF")});
rootTC.detectChanges(); rootTC.detectChanges();
var select = rootTC.query(By.css("select")); var select = rootTC.debugElement.query(By.css("select"));
var sfOption = rootTC.query(By.css("option")); var sfOption = rootTC.debugElement.query(By.css("option"));
expect(select.nativeElement.value).toEqual('SF'); expect(select.nativeElement.value).toEqual('SF');
expect(sfOption.nativeElement.selected).toBe(true); expect(sfOption.nativeElement.selected).toBe(true);
select.nativeElement.value = 'NYC'; select.nativeElement.value = 'NYC';
dispatchEvent(select.nativeElement, "change"); dispatchEvent(select.nativeElement, "change");
expect(rootTC.componentInstance.form.value).toEqual({"city": 'NYC'}); expect(rootTC.debugElement.componentInstance.form.value).toEqual({"city": 'NYC'});
expect(sfOption.nativeElement.selected).toBe(false); expect(sfOption.nativeElement.selected).toBe(false);
async.done(); async.done();
}); });
@ -300,11 +309,12 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"city": new Control("NYC")}); rootTC.debugElement.componentInstance.form =
rootTC.componentInstance.data = ['SF', 'NYC']; new ControlGroup({"city": new Control("NYC")});
rootTC.debugElement.componentInstance.data = ['SF', 'NYC'];
rootTC.detectChanges(); rootTC.detectChanges();
var select = rootTC.query(By.css('select')); var select = rootTC.debugElement.query(By.css('select'));
expect(select.nativeElement.value).toEqual('NYC'); expect(select.nativeElement.value).toEqual('NYC');
async.done(); async.done();
}); });
@ -317,15 +327,16 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = new ControlGroup({"name": new Control("aa")}); rootTC.debugElement.componentInstance.form =
new ControlGroup({"name": new Control("aa")});
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("!aa!"); expect(input.nativeElement.value).toEqual("!aa!");
input.nativeElement.value = "!bb!"; input.nativeElement.value = "!bb!";
dispatchEvent(input.nativeElement, "change"); dispatchEvent(input.nativeElement, "change");
expect(rootTC.componentInstance.form.value).toEqual({"name": "bb"}); expect(rootTC.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
async.done(); async.done();
}); });
})); }));
@ -341,11 +352,11 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
expect(form.valid).toEqual(true); expect(form.valid).toEqual(true);
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
input.nativeElement.value = ""; input.nativeElement.value = "";
dispatchEvent(input.nativeElement, "change"); dispatchEvent(input.nativeElement, "change");
@ -364,11 +375,11 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
expect(form.valid).toEqual(true); expect(form.valid).toEqual(true);
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
input.nativeElement.value = ""; input.nativeElement.value = "";
dispatchEvent(input.nativeElement, "change"); dispatchEvent(input.nativeElement, "change");
@ -392,10 +403,10 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
expect(input.nativeElement.value).toEqual("value"); expect(input.nativeElement.value).toEqual("value");
async.done(); async.done();
}); });
@ -413,9 +424,9 @@ export function main() {
</div>`; </div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")); var input = rootTC.debugElement.query(By.css("input"));
input.nativeElement.value = "updatedValue"; input.nativeElement.value = "updatedValue";
dispatchEvent(input.nativeElement, "change"); dispatchEvent(input.nativeElement, "change");
@ -434,22 +445,22 @@ export function main() {
var t = var t =
`<div [ng-form-model]="form"><input type="text" ng-control="name" [(ng-model)]="name"></div>`; `<div [ng-form-model]="form"><input type="text" ng-control="name" [(ng-model)]="name"></div>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; }); tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = 'oldValue'; rootTC.debugElement.componentInstance.name = 'oldValue';
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue"); expect(input.value).toEqual("oldValue");
input.value = "updatedValue"; input.value = "updatedValue";
dispatchEvent(input, "change"); dispatchEvent(input, "change");
tick(); tick();
expect(rootTC.componentInstance.name).toEqual("updatedValue"); expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
}))); })));
it("should support ng-model for single fields", it("should support ng-model for single fields",
@ -459,21 +470,21 @@ export function main() {
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; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; }); tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.componentInstance.name = "oldValue"; rootTC.debugElement.componentInstance.name = "oldValue";
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue"); expect(input.value).toEqual("oldValue");
input.value = "updatedValue"; input.value = "updatedValue";
dispatchEvent(input, "change"); dispatchEvent(input, "change");
tick(); tick();
expect(rootTC.componentInstance.name).toEqual("updatedValue"); expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
}))); })));
describe("template-driven forms", () => { describe("template-driven forms", () => {
@ -485,14 +496,14 @@ export function main() {
</div> </div>
</form>`; </form>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = null; rootTC.debugElement.componentInstance.name = null;
rootTC.detectChanges(); rootTC.detectChanges();
var form = rootTC.componentViewChildren[0].inject(NgForm); var form = rootTC.debugElement.componentViewChildren[0].inject(NgForm);
expect(form.controls['user']).not.toBeDefined(); expect(form.controls['user']).not.toBeDefined();
tick(); tick();
@ -505,17 +516,17 @@ export function main() {
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => { inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<div><form (ng-submit)="name='updated'"></form></div>`; var t = `<div><form (ng-submit)="name='updated'"></form></div>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = 'old'; rootTC.debugElement.componentInstance.name = 'old';
var form = rootTC.query(By.css("form")); var form = rootTC.debugElement.query(By.css("form"));
dispatchEvent(form.nativeElement, "submit"); dispatchEvent(form.nativeElement, "submit");
tick(); tick();
expect(rootTC.componentInstance.name).toEqual("updated"); expect(rootTC.debugElement.componentInstance.name).toEqual("updated");
}))); })));
it("should not create a template-driven form when ng-no-form is used", it("should not create a template-driven form when ng-no-form is used",
@ -524,10 +535,10 @@ export function main() {
</form>`; </form>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.name = null; rootTC.debugElement.componentInstance.name = null;
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentViewChildren.length).toEqual(0); expect(rootTC.debugElement.componentViewChildren.length).toEqual(0);
async.done(); async.done();
}); });
})); }));
@ -540,19 +551,19 @@ export function main() {
</div> </div>
</form>`; </form>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = 'show'; rootTC.debugElement.componentInstance.name = 'show';
rootTC.detectChanges(); rootTC.detectChanges();
tick(); tick();
var form = rootTC.componentViewChildren[0].inject(NgForm); var form = rootTC.debugElement.componentViewChildren[0].inject(NgForm);
expect(form.controls['login']).toBeDefined(); expect(form.controls['login']).toBeDefined();
rootTC.componentInstance.name = 'hide'; rootTC.debugElement.componentInstance.name = 'hide';
rootTC.detectChanges(); rootTC.detectChanges();
tick(); tick();
@ -568,18 +579,18 @@ export function main() {
</form>`; </form>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = 'show'; rootTC.debugElement.componentInstance.name = 'show';
rootTC.detectChanges(); rootTC.detectChanges();
tick(); tick();
var form = rootTC.componentViewChildren[0].inject(NgForm); var form = rootTC.debugElement.componentViewChildren[0].inject(NgForm);
expect(form.controls['user']).toBeDefined(); expect(form.controls['user']).toBeDefined();
rootTC.componentInstance.name = 'hide'; rootTC.debugElement.componentInstance.name = 'hide';
rootTC.detectChanges(); rootTC.detectChanges();
tick(); tick();
@ -592,22 +603,22 @@ export function main() {
<input type="text" ng-control="name" [(ng-model)]="name"> <input type="text" ng-control="name" [(ng-model)]="name">
</form>`; </form>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = "oldValue"; rootTC.debugElement.componentInstance.name = "oldValue";
rootTC.detectChanges(); rootTC.detectChanges();
tick(); tick();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue"); expect(input.value).toEqual("oldValue");
input.value = "updatedValue"; input.value = "updatedValue";
dispatchEvent(input, "change"); dispatchEvent(input, "change");
tick(); tick();
expect(rootTC.componentInstance.name).toEqual("updatedValue"); expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
}))); })));
@ -615,21 +626,21 @@ export function main() {
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => { inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<div><input type="text" [(ng-model)]="name"></div>`; var t = `<div><input type="text" [(ng-model)]="name"></div>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = "oldValue"; rootTC.debugElement.componentInstance.name = "oldValue";
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(input.value).toEqual("oldValue"); expect(input.value).toEqual("oldValue");
input.value = "updatedValue"; input.value = "updatedValue";
dispatchEvent(input, "change"); dispatchEvent(input, "change");
tick(); tick();
expect(rootTC.componentInstance.name).toEqual("updatedValue"); expect(rootTC.debugElement.componentInstance.name).toEqual("updatedValue");
}))); })));
}); });
@ -642,10 +653,10 @@ export function main() {
var t = `<div><input type="text" [ng-form-control]="form"></div>`; var t = `<div><input type="text" [ng-form-control]="form"></div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(DOM.classList(input)) expect(DOM.classList(input))
.toEqual(['ng-binding', 'ng-invalid', 'ng-pristine', 'ng-untouched']); .toEqual(['ng-binding', 'ng-invalid', 'ng-pristine', 'ng-untouched']);
@ -672,10 +683,10 @@ export function main() {
var t = `<form [ng-form-model]="form"><input type="text" ng-control="name"></form>`; var t = `<form [ng-form-model]="form"><input type="text" ng-control="name"></form>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(DOM.classList(input)) expect(DOM.classList(input))
.toEqual(["ng-binding", "ng-invalid", "ng-pristine", "ng-untouched"]); .toEqual(["ng-binding", "ng-invalid", "ng-pristine", "ng-untouched"]);
@ -700,10 +711,10 @@ export function main() {
var t = `<div><input [(ng-model)]="name" required></div>`; var t = `<div><input [(ng-model)]="name" required></div>`;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => { tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((rootTC) => {
rootTC.componentInstance.name = ""; rootTC.debugElement.componentInstance.name = "";
rootTC.detectChanges(); rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
expect(DOM.classList(input)) expect(DOM.classList(input))
.toEqual(["ng-binding", "ng-invalid", "ng-pristine", "ng-untouched"]); .toEqual(["ng-binding", "ng-invalid", "ng-pristine", "ng-untouched"]);
@ -731,21 +742,21 @@ export function main() {
var t = var t =
`<div><input type="text" [ng-form-control]="form" [(ng-model)]="name"></div>`; `<div><input type="text" [ng-form-control]="form" [(ng-model)]="name"></div>`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.form = form; rootTC.debugElement.componentInstance.form = form;
rootTC.detectChanges(); rootTC.detectChanges();
// In Firefox, effective text selection in the real DOM requires an actual focus // 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. // of the field. This is not an issue in a new HTML document.
if (browserDetection.isFirefox) { if (browserDetection.isFirefox) {
var fakeDoc = DOM.createHtmlDocument(); var fakeDoc = DOM.createHtmlDocument();
DOM.appendChild(fakeDoc.body, rootTC.nativeElement); DOM.appendChild(fakeDoc.body, rootTC.debugElement.nativeElement);
} }
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
input.value = "aa"; input.value = "aa";
input.selectionStart = 1; input.selectionStart = 1;
dispatchEvent(input, "change"); dispatchEvent(input, "change");
@ -760,31 +771,31 @@ export function main() {
it("should update the view when the model is set back to what used to be in the view", it("should update the view when the model is set back to what used to be in the view",
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => { inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<input type="text" [(ng-model)]="name">`; var t = `<input type="text" [(ng-model)]="name">`;
var rootTC; var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then( tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; }); (root) => { rootTC = root; });
tick(); tick();
rootTC.componentInstance.name = ""; rootTC.debugElement.componentInstance.name = "";
rootTC.detectChanges(); rootTC.detectChanges();
// Type "aa" into the input. // Type "aa" into the input.
var input = rootTC.query(By.css("input")).nativeElement; var input = rootTC.debugElement.query(By.css("input")).nativeElement;
input.value = "aa"; input.value = "aa";
input.selectionStart = 1; input.selectionStart = 1;
dispatchEvent(input, "change"); dispatchEvent(input, "change");
tick(); tick();
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.componentInstance.name).toEqual("aa"); expect(rootTC.debugElement.componentInstance.name).toEqual("aa");
// Programatically update the input value to be "bb". // Programatically update the input value to be "bb".
rootTC.componentInstance.name = "bb"; rootTC.debugElement.componentInstance.name = "bb";
tick(); tick();
rootTC.detectChanges(); rootTC.detectChanges();
expect(input.value).toEqual("bb"); expect(input.value).toEqual("bb");
// Programatically set it back to "aa". // Programatically set it back to "aa".
rootTC.componentInstance.name = "aa"; rootTC.debugElement.componentInstance.name = "aa";
tick(); tick();
rootTC.detectChanges(); rootTC.detectChanges();
expect(input.value).toEqual("aa"); expect(input.value).toEqual("aa");

View File

@ -31,7 +31,8 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(App).then((tc) => { tcb.createAsync(App).then((tc) => {
tc.detectChanges(); tc.detectChanges();
expect(asNativeElements(tc.componentViewChildren)).toHaveText('frame(lock)'); expect(asNativeElements(tc.debugElement.componentViewChildren))
.toHaveText('frame(lock)');
async.done(); async.done();
}); });
})); }));

View File

@ -2,6 +2,7 @@ import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {SelectorMatcher} from 'angular2/src/core/render/dom/compiler/selector'; import {SelectorMatcher} from 'angular2/src/core/render/dom/compiler/selector';
import {CssSelector} from 'angular2/src/core/render/dom/compiler/selector'; import {CssSelector} from 'angular2/src/core/render/dom/compiler/selector';
import {ListWrapper, MapWrapper} from 'angular2/src/core/facade/collection';
export function main() { export function main() {
describe('SelectorMatcher', () => { describe('SelectorMatcher', () => {

View File

@ -15,6 +15,7 @@ import {
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline'; import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import { import {
ProtoViewBuilder, ProtoViewBuilder,
ElementBinderBuilder ElementBinderBuilder

View File

@ -3,6 +3,7 @@ import {
TextInterpolationParser TextInterpolationParser
} from 'angular2/src/core/render/dom/compiler/text_interpolation_parser'; } from 'angular2/src/core/render/dom/compiler/text_interpolation_parser';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline'; import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {Lexer, Parser, ASTWithSource} from 'angular2/src/core/change_detection/change_detection'; import {Lexer, Parser, ASTWithSource} from 'angular2/src/core/change_detection/change_detection';
import {IgnoreChildrenStep} from './pipeline_spec'; import {IgnoreChildrenStep} from './pipeline_spec';
import { import {

View File

@ -16,6 +16,7 @@ import {StyleUrlResolver} from 'angular2/src/core/render/dom/compiler/style_url_
import {UrlResolver} from 'angular2/src/core/services/url_resolver'; import {UrlResolver} from 'angular2/src/core/services/url_resolver';
import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async'; import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {XHR} from 'angular2/src/core/render/xhr'; import {XHR} from 'angular2/src/core/render/xhr';
import {MockXHR} from 'angular2/src/core/render/xhr_mock'; import {MockXHR} from 'angular2/src/core/render/xhr_mock';
import {ViewDefinition} from 'angular2/src/core/render/api'; import {ViewDefinition} from 'angular2/src/core/render/api';

View File

@ -13,6 +13,7 @@ import {
SpyObject, SpyObject,
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {MapWrapper} from 'angular2/src/core/facade/collection';
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DomTestbed, TestRootView, elRef} from './dom_testbed'; import {DomTestbed, TestRootView, elRef} from './dom_testbed';

View File

@ -1,4 +1,5 @@
import { import {
RootTestComponent,
AsyncTestCompleter, AsyncTestCompleter,
TestComponentBuilder, TestComponentBuilder,
beforeEach, beforeEach,
@ -58,7 +59,8 @@ export function main() {
describe('Router lifecycle hooks', () => { describe('Router lifecycle hooks', () => {
var tcb: TestComponentBuilder; var tcb: TestComponentBuilder;
var rootTC, rtr; var rootTC: RootTestComponent;
var rtr;
beforeEachBindings(() => [ beforeEachBindings(() => [
Pipeline, Pipeline,
@ -94,7 +96,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/on-activate')) .then((_) => rtr.navigateByUrl('/on-activate'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('activate cmp'); expect(rootTC.debugElement.nativeElement).toHaveText('activate cmp');
expect(log).toEqual(['activate: null -> /on-activate']); expect(log).toEqual(['activate: null -> /on-activate']);
async.done(); async.done();
}); });
@ -113,7 +115,7 @@ export function main() {
rtr.navigateByUrl('/parent-activate/child-activate') rtr.navigateByUrl('/parent-activate/child-activate')
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('parent {activate cmp}'); expect(rootTC.debugElement.nativeElement).toHaveText('parent {activate cmp}');
expect(log).toEqual([ expect(log).toEqual([
'parent activate: null -> /parent-activate', 'parent activate: null -> /parent-activate',
'activate: null -> /child-activate' 'activate: null -> /child-activate'
@ -130,7 +132,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/a')) .then((_) => rtr.navigateByUrl('/a'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A'); expect(rootTC.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual(['deactivate: /on-deactivate -> /a']); expect(log).toEqual(['deactivate: /on-deactivate -> /a']);
async.done(); async.done();
}); });
@ -146,12 +148,12 @@ export function main() {
if (ev.startsWith('deactivate')) { if (ev.startsWith('deactivate')) {
completer.resolve(true); completer.resolve(true);
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('parent {deactivate cmp}'); expect(rootTC.debugElement.nativeElement).toHaveText('parent {deactivate cmp}');
} }
}); });
rtr.navigateByUrl('/a').then((_) => { rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A'); expect(rootTC.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual([ expect(log).toEqual([
'deactivate: /child-deactivate -> null', 'deactivate: /child-deactivate -> null',
'parent deactivate: /parent-deactivate -> /a' 'parent deactivate: /parent-deactivate -> /a'
@ -169,14 +171,14 @@ export function main() {
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(log).toEqual([]); expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {A}'); expect(rootTC.debugElement.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1); expect(cmpInstanceCount).toBe(1);
}) })
.then((_) => rtr.navigateByUrl('/on-reuse/2/b')) .then((_) => rtr.navigateByUrl('/on-reuse/2/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(log).toEqual(['reuse: /on-reuse/1 -> /on-reuse/2']); expect(log).toEqual(['reuse: /on-reuse/1 -> /on-reuse/2']);
expect(rootTC.nativeElement).toHaveText('reuse {B}'); expect(rootTC.debugElement.nativeElement).toHaveText('reuse {B}');
expect(cmpInstanceCount).toBe(1); expect(cmpInstanceCount).toBe(1);
async.done(); async.done();
}); });
@ -191,14 +193,14 @@ export function main() {
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(log).toEqual([]); expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {A}'); expect(rootTC.debugElement.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1); expect(cmpInstanceCount).toBe(1);
}) })
.then((_) => rtr.navigateByUrl('/never-reuse/2/b')) .then((_) => rtr.navigateByUrl('/never-reuse/2/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(log).toEqual([]); expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {B}'); expect(rootTC.debugElement.nativeElement).toHaveText('reuse {B}');
expect(cmpInstanceCount).toBe(2); expect(cmpInstanceCount).toBe(2);
async.done(); async.done();
}); });
@ -217,7 +219,7 @@ export function main() {
rtr.navigateByUrl('/can-activate/a') rtr.navigateByUrl('/can-activate/a')
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canActivate {A}'); expect(rootTC.debugElement.nativeElement).toHaveText('canActivate {A}');
expect(log).toEqual(['canActivate: null -> /can-activate']); expect(log).toEqual(['canActivate: null -> /can-activate']);
async.done(); async.done();
}); });
@ -237,7 +239,7 @@ export function main() {
rtr.navigateByUrl('/can-activate/a') rtr.navigateByUrl('/can-activate/a')
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(''); expect(rootTC.debugElement.nativeElement).toHaveText('');
expect(log).toEqual(['canActivate: null -> /can-activate']); expect(log).toEqual(['canActivate: null -> /can-activate']);
async.done(); async.done();
}); });
@ -251,7 +253,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/can-deactivate/a')) .then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}'); expect(rootTC.debugElement.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual([]); expect(log).toEqual([]);
ObservableWrapper.subscribe<string>(eventBus, (ev) => { ObservableWrapper.subscribe<string>(eventBus, (ev) => {
@ -262,7 +264,7 @@ export function main() {
rtr.navigateByUrl('/a').then((_) => { rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A'); expect(rootTC.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']); expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
async.done(); async.done();
}); });
@ -276,7 +278,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/can-deactivate/a')) .then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}'); expect(rootTC.debugElement.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual([]); expect(log).toEqual([]);
ObservableWrapper.subscribe<string>(eventBus, (ev) => { ObservableWrapper.subscribe<string>(eventBus, (ev) => {
@ -287,7 +289,7 @@ export function main() {
rtr.navigateByUrl('/a').then((_) => { rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}'); expect(rootTC.debugElement.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']); expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
async.done(); async.done();
}); });

View File

@ -1,4 +1,5 @@
import { import {
RootTestComponent,
AsyncTestCompleter, AsyncTestCompleter,
TestComponentBuilder, TestComponentBuilder,
beforeEach, beforeEach,
@ -42,7 +43,8 @@ export function main() {
describe('navigation', () => { describe('navigation', () => {
var tcb: TestComponentBuilder; var tcb: TestComponentBuilder;
var rootTC, rtr; var rootTC: RootTestComponent;
var rtr;
beforeEachBindings(() => [ beforeEachBindings(() => [
Pipeline, Pipeline,
@ -78,7 +80,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/test')) .then((_) => rtr.navigateByUrl('/test'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello'); expect(rootTC.debugElement.nativeElement).toHaveText('hello');
async.done(); async.done();
}); });
})); }));
@ -91,12 +93,12 @@ export function main() {
.then((_) => rtr.navigateByUrl('/user/brian')) .then((_) => rtr.navigateByUrl('/user/brian'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello brian'); expect(rootTC.debugElement.nativeElement).toHaveText('hello brian');
}) })
.then((_) => rtr.navigateByUrl('/user/igor')) .then((_) => rtr.navigateByUrl('/user/igor'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello igor'); expect(rootTC.debugElement.nativeElement).toHaveText('hello igor');
async.done(); async.done();
}); });
})); }));
@ -108,7 +110,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/a/b')) .then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('outer { inner { hello } }'); expect(rootTC.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
async.done(); async.done();
}); });
})); }));
@ -120,7 +122,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/a/b')) .then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('outer { inner { hello } }'); expect(rootTC.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
async.done(); async.done();
}); });
})); }));
@ -136,7 +138,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/original')) .then((_) => rtr.navigateByUrl('/original'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello'); expect(rootTC.debugElement.nativeElement).toHaveText('hello');
expect(location.urlChanges).toEqual(['/redirected']); expect(location.urlChanges).toEqual(['/redirected']);
async.done(); async.done();
}); });
@ -150,13 +152,14 @@ export function main() {
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1); expect(cmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello rado }'); expect(rootTC.debugElement.nativeElement).toHaveText('team angular { hello rado }');
}) })
.then((_) => rtr.navigateByUrl('/team/angular/user/victor')) .then((_) => rtr.navigateByUrl('/team/angular/user/victor'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1); expect(cmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello victor }'); expect(rootTC.debugElement.nativeElement)
.toHaveText('team angular { hello victor }');
async.done(); async.done();
}); });
})); }));
@ -170,14 +173,14 @@ export function main() {
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1); expect(cmpInstanceCount).toBe(1);
expect(childCmpInstanceCount).toBe(1); expect(childCmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello rado }'); expect(rootTC.debugElement.nativeElement).toHaveText('team angular { hello rado }');
}) })
.then((_) => rtr.navigateByUrl('/team/dart/user/rado')) .then((_) => rtr.navigateByUrl('/team/dart/user/rado'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(cmpInstanceCount).toBe(2); expect(cmpInstanceCount).toBe(2);
expect(childCmpInstanceCount).toBe(2); expect(childCmpInstanceCount).toBe(2);
expect(rootTC.nativeElement).toHaveText('team dart { hello rado }'); expect(rootTC.debugElement.nativeElement).toHaveText('team dart { hello rado }');
async.done(); async.done();
}); });
})); }));
@ -190,7 +193,8 @@ export function main() {
.then((_) => rtr.navigateByUrl('/route-data')) .then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify({'isAdmin': true})); expect(rootTC.debugElement.nativeElement)
.toHaveText(Json.stringify({'isAdmin': true}));
async.done(); async.done();
}); });
})); }));
@ -205,7 +209,8 @@ export function main() {
.then((_) => rtr.navigateByUrl('/route-data')) .then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify({'isAdmin': true})); expect(rootTC.debugElement.nativeElement)
.toHaveText(Json.stringify({'isAdmin': true}));
async.done(); async.done();
}); });
})); }));
@ -218,7 +223,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/route-data-default')) .then((_) => rtr.navigateByUrl('/route-data-default'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('null'); expect(rootTC.debugElement.nativeElement).toHaveText('null');
async.done(); async.done();
}); });
})); }));
@ -231,7 +236,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/route-data-array')) .then((_) => rtr.navigateByUrl('/route-data-array'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify([1, 2, 3])); expect(rootTC.debugElement.nativeElement).toHaveText(Json.stringify([1, 2, 3]));
async.done(); async.done();
}); });
})); }));
@ -245,7 +250,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/route-data-string')) .then((_) => rtr.navigateByUrl('/route-data-string'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify('hello world')); expect(rootTC.debugElement.nativeElement).toHaveText(Json.stringify('hello world'));
async.done(); async.done();
}); });
})); }));
@ -257,7 +262,7 @@ export function main() {
.then((_) => rtr.navigateByUrl('/hello(modal)')) .then((_) => rtr.navigateByUrl('/hello(modal)'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('main {hello} | aux {modal}'); expect(rootTC.debugElement.nativeElement).toHaveText('main {hello} | aux {modal}');
async.done(); async.done();
}); });
})); }));

View File

@ -71,9 +71,9 @@ export function main() {
it('should rethrow exceptions from component constructors', it('should rethrow exceptions from component constructors',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => { inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(AppCmp).then((rootTC) => { tcb.createAsync(AppCmp).then((rootTC) => {
var router = rootTC.componentInstance.router; var router = rootTC.debugElement.componentInstance.router;
PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => { PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => {
expect(rootTC.nativeElement).toHaveText('outer { oh no }'); expect(rootTC.debugElement.nativeElement).toHaveText('outer { oh no }');
expect(error).toContainError('oops!'); expect(error).toContainError('oops!');
async.done(); async.done();
}); });
@ -89,7 +89,7 @@ export function main() {
tcb.createAsync(HierarchyAppCmp) tcb.createAsync(HierarchyAppCmp)
.then((rootTC) => { .then((rootTC) => {
var router = rootTC.componentInstance.router; var router = rootTC.debugElement.componentInstance.router;
var position = 0; var position = 0;
var flipped = false; var flipped = false;
var history = var history =
@ -100,8 +100,8 @@ export function main() {
] ]
router.subscribe((_) => { router.subscribe((_) => {
var location = rootTC.componentInstance.location; var location = rootTC.debugElement.componentInstance.location;
var element = rootTC.nativeElement; var element = rootTC.debugElement.nativeElement;
var path = location.path(); var path = location.path();
var entry = history[position]; var entry = history[position];
@ -140,10 +140,12 @@ export function main() {
tcb.createAsync(HierarchyAppCmp) tcb.createAsync(HierarchyAppCmp)
.then((rootTC) => { .then((rootTC) => {
var router = rootTC.componentInstance.router; var router = rootTC.debugElement.componentInstance.router;
router.subscribe((_) => { router.subscribe((_) => {
expect(rootTC.nativeElement).toHaveText('root { parent { hello } }'); expect(rootTC.debugElement.nativeElement)
expect(rootTC.componentInstance.location.path()).toEqual('/parent/child'); .toHaveText('root { parent { hello } }');
expect(rootTC.debugElement.componentInstance.location.path())
.toEqual('/parent/child');
async.done(); async.done();
}); });
router.navigateByUrl('/parent/child'); router.navigateByUrl('/parent/child');
@ -158,10 +160,11 @@ export function main() {
tcb.createAsync(HierarchyAppCmp) tcb.createAsync(HierarchyAppCmp)
.then((rootTC) => { .then((rootTC) => {
var router = rootTC.componentInstance.router; var router = rootTC.debugElement.componentInstance.router;
router.subscribe((_) => { router.subscribe((_) => {
expect(rootTC.nativeElement).toHaveText('root { parent { hello } }'); expect(rootTC.debugElement.nativeElement)
expect(rootTC.componentInstance.location.path()) .toHaveText('root { parent { hello } }');
expect(rootTC.debugElement.componentInstance.location.path())
.toEqual('/my/app/parent/child'); .toEqual('/my/app/parent/child');
async.done(); async.done();
}); });
@ -180,11 +183,12 @@ export function main() {
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => { inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(QueryStringAppCmp) tcb.createAsync(QueryStringAppCmp)
.then((rootTC) => { .then((rootTC) => {
var router = rootTC.componentInstance.router; var router = rootTC.debugElement.componentInstance.router;
router.subscribe((_) => { router.subscribe((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('qParam = search-for-something'); expect(rootTC.debugElement.nativeElement)
.toHaveText('qParam = search-for-something');
/* /*
expect(applicationRef.hostComponent.location.path()) expect(applicationRef.hostComponent.location.path())
.toEqual('/qs?q=search-for-something');*/ .toEqual('/qs?q=search-for-something');*/

View File

@ -1,4 +1,5 @@
import { import {
RootTestComponent,
AsyncTestCompleter, AsyncTestCompleter,
beforeEach, beforeEach,
ddescribe, ddescribe,
@ -42,7 +43,8 @@ import {DOM} from 'angular2/src/core/dom/dom_adapter';
export function main() { export function main() {
describe('router-link directive', function() { describe('router-link directive', function() {
var tcb: TestComponentBuilder; var tcb: TestComponentBuilder;
var rootTC, router, location; var rootTC: RootTestComponent;
var router, location;
beforeEachBindings(() => [ beforeEachBindings(() => [
Pipeline, Pipeline,
@ -104,10 +106,11 @@ export function main() {
[new Route({path: '/user/:name', component: UserCmp, as: 'user'})])) [new Route({path: '/user/:name', component: UserCmp, as: 'user'})]))
.then((_) => router.navigateByUrl('/a/b')) .then((_) => router.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.componentInstance.name = 'brian'; rootTC.debugElement.componentInstance.name = 'brian';
rootTC.detectChanges(); rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('brian'); expect(rootTC.debugElement.nativeElement).toHaveText('brian');
expect(DOM.getAttribute(rootTC.componentViewChildren[0].nativeElement, 'href')) expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
'href'))
.toEqual('/user/brian'); .toEqual('/user/brian');
async.done(); async.done();
}); });
@ -121,9 +124,10 @@ export function main() {
.then((_) => router.navigateByUrl('/page/1')) .then((_) => router.navigateByUrl('/page/1'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getAttribute( expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
rootTC.componentViewChildren[1].componentViewChildren[0].nativeElement, .componentViewChildren[0]
'href')) .nativeElement,
'href'))
.toEqual('/page/2'); .toEqual('/page/2');
async.done(); async.done();
}); });
@ -142,9 +146,10 @@ export function main() {
.then((_) => router.navigate(['/child-with-grandchild'])) .then((_) => router.navigate(['/child-with-grandchild']))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getAttribute( expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
rootTC.componentViewChildren[1].componentViewChildren[0].nativeElement, .componentViewChildren[0]
'href')) .nativeElement,
'href'))
.toEqual('/child-with-grandchild/grandchild'); .toEqual('/child-with-grandchild/grandchild');
async.done(); async.done();
}); });
@ -158,12 +163,13 @@ export function main() {
.then((_) => router.navigateByUrl('/book/1984/page/1')) .then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getAttribute( expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
rootTC.componentViewChildren[1].componentViewChildren[0].nativeElement, .componentViewChildren[0]
'href')) .nativeElement,
'href'))
.toEqual('/book/1984/page/100'); .toEqual('/book/1984/page/100');
expect(DOM.getAttribute(rootTC.componentViewChildren[1] expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
.componentViewChildren[2] .componentViewChildren[2]
.componentViewChildren[0] .componentViewChildren[0]
.nativeElement, .nativeElement,
@ -184,7 +190,7 @@ export function main() {
<a [router-link]="['./better-child']" class="better-child-link">Better Child</a> <a [router-link]="['./better-child']" class="better-child-link">Better Child</a>
<router-outlet></router-outlet>`)) <router-outlet></router-outlet>`))
.then((_) => { .then((_) => {
var element = rootTC.nativeElement; var element = rootTC.debugElement.nativeElement;
rootTC.detectChanges(); rootTC.detectChanges();
@ -219,7 +225,7 @@ export function main() {
<a [router-link]="['./child-with-grandchild/grandchild']" class="child-with-grandchild-link">Better Child</a> <a [router-link]="['./child-with-grandchild/grandchild']" class="child-with-grandchild-link">Better Child</a>
<router-outlet></router-outlet>`)) <router-outlet></router-outlet>`))
.then((_) => { .then((_) => {
var element = rootTC.nativeElement; var element = rootTC.debugElement.nativeElement;
rootTC.detectChanges(); rootTC.detectChanges();
@ -251,7 +257,7 @@ export function main() {
describe('when clicked', () => { describe('when clicked', () => {
var clickOnElement = function(view) { var clickOnElement = function(view) {
var anchorEl = rootTC.componentViewChildren[0].nativeElement; var anchorEl = rootTC.debugElement.componentViewChildren[0].nativeElement;
var dispatchedEvent = DOM.createMouseEvent('click'); var dispatchedEvent = DOM.createMouseEvent('click');
DOM.dispatchEvent(anchorEl, dispatchedEvent); DOM.dispatchEvent(anchorEl, dispatchedEvent);
return dispatchedEvent; return dispatchedEvent;
@ -300,8 +306,8 @@ export function main() {
}); });
} }
function getHref(tc) { function getHref(tc: RootTestComponent) {
return DOM.getAttribute(tc.componentViewChildren[0].nativeElement, 'href'); return DOM.getAttribute(tc.debugElement.componentViewChildren[0].nativeElement, 'href');
} }
@Component({selector: 'my-comp'}) @Component({selector: 'my-comp'})

View File

@ -10,6 +10,8 @@ import {
SpyObject SpyObject
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {Map, StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {RouteRecognizer} from 'angular2/src/router/route_recognizer'; import {RouteRecognizer} from 'angular2/src/router/route_recognizer';
import {ComponentInstruction} from 'angular2/src/router/instruction'; import {ComponentInstruction} from 'angular2/src/router/instruction';

View File

@ -51,7 +51,7 @@ export function main() {
tcb.createAsync(TestComponent) tcb.createAsync(TestComponent)
.then((testComponent) => { .then((testComponent) => {
testComponent.detectChanges(); testComponent.detectChanges();
let anchorElement = testComponent.query(By.css('a')).nativeElement; let anchorElement = testComponent.debugElement.query(By.css('a')).nativeElement;
expect(DOM.getAttribute(anchorElement, 'href')).toEqual('/detail'); expect(DOM.getAttribute(anchorElement, 'href')).toEqual('/detail');
async.done(); async.done();
}); });
@ -65,7 +65,7 @@ export function main() {
.then((testComponent) => { .then((testComponent) => {
testComponent.detectChanges(); testComponent.detectChanges();
// TODO: shouldn't this be just 'click' rather than '^click'? // TODO: shouldn't this be just 'click' rather than '^click'?
testComponent.query(By.css('a')).triggerEventHandler('click', null); testComponent.debugElement.query(By.css('a')).triggerEventHandler('click', null);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction); expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done(); async.done();
}); });

View File

@ -93,66 +93,66 @@ class TestViewBindingsComp {
export function main() { export function main() {
describe('test component builder', function() { describe('test component builder', function() {
it('should instantiate a component with valid DOM', it('should instantiate a component with valid DOM',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(ChildComp).then((rootTestComponent) => { tcb.createAsync(ChildComp).then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement).toHaveText('Original Child'); expect(rootTestComponent.debugElement.nativeElement).toHaveText('Original Child');
async.done(); async.done();
}); });
})); }));
it('should allow changing members of the component', it('should allow changing members of the component',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.createAsync(MyIfComp).then((rootTestComponent) => { tcb.createAsync(MyIfComp).then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement).toHaveText('MyIf()'); expect(rootTestComponent.debugElement.nativeElement).toHaveText('MyIf()');
rootTestComponent.componentInstance.showMore = true; rootTestComponent.debugElement.componentInstance.showMore = true;
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement).toHaveText('MyIf(More)'); expect(rootTestComponent.debugElement.nativeElement).toHaveText('MyIf(More)');
async.done(); async.done();
}); });
})); }));
it('should override a template', it('should override a template',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MockChildComp, '<span>Mock</span>') tcb.overrideTemplate(MockChildComp, '<span>Mock</span>')
.createAsync(MockChildComp) .createAsync(MockChildComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement).toHaveText('Mock'); expect(rootTestComponent.debugElement.nativeElement).toHaveText('Mock');
async.done(); async.done();
}); });
})); }));
it('should override a view', it('should override a view',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(ChildComp, tcb.overrideView(ChildComp,
new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'})) new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
.createAsync(ChildComp) .createAsync(ChildComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement).toHaveText('Modified Child'); expect(rootTestComponent.debugElement.nativeElement).toHaveText('Modified Child');
async.done(); async.done();
}); });
})); }));
it('should override component dependencies', it('should override component dependencies',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideDirective(ParentComp, ChildComp, MockChildComp) tcb.overrideDirective(ParentComp, ChildComp, MockChildComp)
.createAsync(ParentComp) .createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement).toHaveText('Parent(Mock)'); expect(rootTestComponent.debugElement.nativeElement).toHaveText('Parent(Mock)');
async.done(); async.done();
}); });
@ -160,14 +160,14 @@ export function main() {
it("should override child component's dependencies", it("should override child component's dependencies",
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp) tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp)
.overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp) .overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp)
.createAsync(ParentComp) .createAsync(ParentComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement) expect(rootTestComponent.debugElement.nativeElement)
.toHaveText('Parent(Original Child(ChildChild Mock))'); .toHaveText('Parent(Original Child(ChildChild Mock))');
async.done(); async.done();
@ -175,13 +175,13 @@ export function main() {
})); }));
it('should override a binding', it('should override a binding',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideBindings(TestBindingsComp, [bind(FancyService).toClass(MockFancyService)]) tcb.overrideBindings(TestBindingsComp, [bind(FancyService).toClass(MockFancyService)])
.createAsync(TestBindingsComp) .createAsync(TestBindingsComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement) expect(rootTestComponent.debugElement.nativeElement)
.toHaveText('injected value: mocked out value'); .toHaveText('injected value: mocked out value');
async.done(); async.done();
}); });
@ -189,14 +189,14 @@ export function main() {
it('should override a viewBinding', it('should override a viewBinding',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideViewBindings(TestViewBindingsComp, tcb.overrideViewBindings(TestViewBindingsComp,
[bind(FancyService).toClass(MockFancyService)]) [bind(FancyService).toClass(MockFancyService)])
.createAsync(TestViewBindingsComp) .createAsync(TestViewBindingsComp)
.then((rootTestComponent) => { .then((rootTestComponent) => {
rootTestComponent.detectChanges(); rootTestComponent.detectChanges();
expect(rootTestComponent.nativeElement) expect(rootTestComponent.debugElement.nativeElement)
.toHaveText('injected value: mocked out value'); .toHaveText('injected value: mocked out value');
async.done(); async.done();
}); });

View File

@ -2,9 +2,3 @@
export * from './test'; export * from './test';
export * from './src/test_lib/utils'; export * from './src/test_lib/utils';
export * from './src/test_lib/fake_async'; export * from './src/test_lib/fake_async';
export {ComponentRef, HostViewRef} from './src/core/compiler';
// This interface is referenced by TestComponents, however we can't export it directly from router
// because router pulls in dart:html & dart:js and we import test_lib in standalone VM tests
// so we re-create the interface here.
export interface InjectableReference {}

View File

@ -1,16 +1,6 @@
export * from '../src/core/facade'; export * from '../src/core/facade';
export * from "../src/web_workers/ui/application";
export * from '../src/core/zone'; export * from '../src/core/zone';
export * from "../src/web_workers/ui/application";
export * from "../src/web_workers/shared/client_message_broker"; export * from "../src/web_workers/shared/client_message_broker";
export * from "../src/web_workers/shared/service_message_broker"; export * from "../src/web_workers/shared/service_message_broker";
export * from "../src/web_workers/shared/serializer"; export {PRIMITIVE} from '../src/web_workers/shared/serializer';
export * from '../src/web_workers/shared/render_proto_view_ref_store';
export * from '../src/web_workers/shared/render_view_with_fragments_store';
export * from '../src/core/render/api';
export * from '../src/core/change_detection';
export * from '../src/core/di';
export {Reflector, ReflectionInfo} from '../src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from '../src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from '../src/core/reflection/types';

View File

@ -7,6 +7,7 @@ export * from '../src/core/facade';
// Do not export application in web_worker, // Do not export application in web_worker,
// web_worker exports its own // web_worker exports its own
// export * from '../src/core/application'; // export * from '../src/core/application';
export * from '../src/core/application_ref';
export * from '../src/core/services'; export * from '../src/core/services';
export * from '../src/core/compiler'; export * from '../src/core/compiler';
export * from '../src/core/lifecycle'; export * from '../src/core/lifecycle';
@ -14,22 +15,23 @@ export * from '../src/core/zone';
// Do not export render in web_worker // Do not export render in web_worker
// export * from '../src/core/render'; // export * from '../src/core/render';
// Add special import for just render API // Add special import for just render API
export * from '../src/core/application_ref'; // TODO: Hard coded exports from render that need to be cleaned up
export * from '../src/core/application_tokens'; export {
export * from '../src/core/render/api'; RenderEventDispatcher,
Renderer,
RenderElementRef,
RenderViewRef,
RenderProtoViewRef,
RenderFragmentRef,
RenderViewWithFragments
} from '../src/core/render/render';
export * from '../src/core/directives'; export * from '../src/core/directives';
export * from '../src/core/forms'; export * from '../src/core/forms';
export * from '../src/core/debug'; export * from '../src/core/debug';
export * from '../src/core/change_detection'; export * from '../src/core/change_detection';
export * from '../profile'; export * from '../profile';
export * from '../src/web_workers/worker/application'; export * from '../src/web_workers/worker/application';
export * from '../src/web_workers/shared/client_message_broker'; export * from '../src/web_workers/shared/client_message_broker';
export * from '../src/web_workers/shared/service_message_broker'; export * from '../src/web_workers/shared/service_message_broker';
export * from '../src/web_workers/shared/serializer'; export {PRIMITIVE} from '../src/web_workers/shared/serializer';
export * from '../src/web_workers/shared/render_proto_view_ref_store';
export * from '../src/web_workers/shared/render_view_with_fragments_store';
export {Reflector, ReflectionInfo} from '../src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from '../src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from '../src/core/reflection/types';

View File

@ -8,8 +8,14 @@ var broker = instance.app.createClientMessageBroker(ECHO_CHANNEL, false);
document.getElementById("send_echo") document.getElementById("send_echo")
.addEventListener("click", (e) => { .addEventListener("click", (e) => {
var val = (<HTMLInputElement>document.getElementById("echo_input")).value; var val = (<HTMLInputElement>document.getElementById("echo_input")).value;
var fnArg = new FnArg(val, PRIMITIVE); // TODO(jteplitz602): Replace default constructors with real constructors
var args = new UiArguments("echo", [fnArg]); // once they're in the .d.ts file (#3926)
var args = new UiArguments();
args.method = "echo";
var fnArg = new FnArg();
fnArg.value = val;
fnArg.type = PRIMITIVE;
args.args = [fnArg];
broker.runOnService(args, PRIMITIVE) broker.runOnService(args, PRIMITIVE)
.then((echo_result: string) => { .then((echo_result: string) => {

View File

@ -3,8 +3,7 @@ library angular2.transform.common.directive_metadata_reader;
import 'package:analyzer/analyzer.dart'; import 'package:analyzer/analyzer.dart';
import 'package:analyzer/src/generated/element.dart'; import 'package:analyzer/src/generated/element.dart';
import 'package:angular2/src/core/render/api.dart'; import 'package:angular2/src/core/render/api.dart';
import 'package:angular2/src/core/change_detection/change_detection.dart' import 'package:angular2/src/core/change_detection/change_detection.dart';
show ChangeDetectionStrategy;
/// Reads [RenderDirectiveMetadata] from the `node`. `node` is expected to be an /// Reads [RenderDirectiveMetadata] from the `node`. `node` is expected to be an
/// instance of [ClassDeclaration] (a class which may have a [Directive] or /// instance of [ClassDeclaration] (a class which may have a [Directive] or