feat(debug): replace DebugElement with new Debug DOM

Now, using `ng.probe(element)` in the browser console returns
a DebugElement when in dev mode.

`ComponentFixture#debugElement` also returns a new DebugElement.

Breaking Change:

This is a breaking change for unit tests. The API for the DebugElement
has changed. Now, there is a DebugElement or DebugNode for every node
in the DOM, not only nodes with an ElementRef. `componentViewChildren` is
removed, and `childNodes` is a list of ElementNodes corresponding to every
child in the DOM. `query` no longer takes a scope parameter, since
the entire rendered DOM is included in the `childNodes`.

Before:

```
componentFixture.debugElement.componentViewChildren[0];
```

After
```
// Depending on the DOM structure of your component, the
// index may have changed or the first component child
// may be a sub-child.
componentFixture.debugElement.children[0];
```

Before:

```
debugElement.query(By.css('div'), Scope.all());
```

After:

```
debugElement.query(By.css('div'));
```

Before:

```
componentFixture.debugElement.elementRef;
```

After:

```
componentFixture.elementRef;
```
This commit is contained in:
Julie Ralph
2016-01-13 21:35:21 -08:00
committed by Alex Eagle
parent ae7d2ab515
commit e1bf3d33f8
45 changed files with 1243 additions and 1220 deletions

View File

@ -119,17 +119,20 @@ const CORE = [
'CyclicDependencyError.constructor(injector:Injector, key:Key)',
'DebugElement',
'DebugElement.children:DebugElement[]',
'DebugElement.componentInstance:any',
'DebugElement.componentViewChildren:DebugElement[]',
'DebugElement.elementRef:ElementRef',
'DebugElement.getDirectiveInstance(directiveIndex:number):any',
'DebugElement.getLocal(name:string):any',
'DebugElement.hasDirective(type:Type):boolean',
'DebugElement.inject(type:Type):any',
'DebugElement.nativeElement:any',
'DebugElement.query(predicate:Predicate<DebugElement>, scope:Function):DebugElement',
'DebugElement.queryAll(predicate:Predicate<DebugElement>, scope:Function):DebugElement[]',
'DebugElement.triggerEventHandler(eventName:string, eventObj:Event):void',
'DebugElement.addChild(child:DebugNode):any',
'DebugElement.attributes:Map<string, any>',
'DebugElement.childNodes:DebugNode[]',
'DebugElement.constructor(nativeNode:any, parent:any)',
'DebugElement.insertChildrenAfter(child:DebugNode, newChildren:DebugNode[]):any',
'DebugElement.name:string',
'DebugElement.properties:Map<string, any>',
'DebugElement.query(predicate:Predicate<DebugElement>):DebugElement',
'DebugElement.queryAll(predicate:Predicate<DebugElement>):DebugElement[]',
'DebugElement.queryAllNodes(predicate:Predicate<DebugNode>):DebugNode[]',
'DebugElement.removeChild(child:DebugNode):any',
'DebugElement.triggerEventHandler(eventName:string, eventObj:Event):any',
'asNativeElements(debugEls:DebugElement[]):any',
'Dependency',
'Dependency.constructor(key:Key, optional:boolean, lowerBoundVisibility:any, upperBoundVisibility:any, properties:any[])',
'Dependency.fromKey(key:Key):Dependency',
@ -389,6 +392,7 @@ const CORE = [
'Renderer.setElementProperty(renderElement:any, propertyName:string, propertyValue:any):any',
'Renderer.setElementStyle(renderElement:any, styleName:string, styleValue:string):any',
'Renderer.setText(renderNode:any, text:string):any',
'Renderer.setElementDebugInfo(renderElement:any, info:RenderDebugInfo):any',
'ResolvedBinding',
'ResolvedFactory',
'ResolvedFactory.constructor(factory:Function, dependencies:Dependency[])',
@ -398,10 +402,6 @@ const CORE = [
'ResolvedProvider.resolvedFactories:ResolvedFactory[]',
'RootRenderer',
'RootRenderer.renderComponent(componentType:RenderComponentType):Renderer',
'Scope',
'Scope.all(debugElement:DebugElement):DebugElement[]',
'Scope.light(debugElement:DebugElement):DebugElement[]',
'Scope.view(debugElement:DebugElement):DebugElement[]',
'SelfFactory',
'SelfMetadata',
'SelfMetadata.toString():string',
@ -489,7 +489,6 @@ const CORE = [
'WrappedValue.constructor(wrapped:any)',
'WrappedValue.wrap(value:any):WrappedValue',
'ZeroArgFunction',
'asNativeElements(arr:DebugElement[]):any[]',
'bind(token:any):ProviderBuilder',
'const APPLICATION_COMMON_PROVIDERS:Array<Type|Provider|any[]>',
'const APP_COMPONENT:OpaqueToken',
@ -503,7 +502,6 @@ const CORE = [
'createNgZone():NgZone',
'enableProdMode():any',
'forwardRef(forwardRefFn:ForwardRefFn):Type',
'inspectElement(elementRef:ElementRef):DebugElement',
'platform(providers:Array<Type|Provider|any[]>):PlatformRef',
'provide(token:any, {useClass,useValue,useExisting,useFactory,deps,multi}:{useClass?:Type, useValue?:any, useExisting?:any, useFactory?:Function, deps?:Object[], multi?:boolean}):Provider',
'resolveForwardRef(type:any):any',
@ -1059,11 +1057,11 @@ const BROWSER = [
'bootstrapStatic(appComponentType:Type, customProviders:Array<any>, initReflector:Function):Promise<ComponentRef>',
'const BROWSER_APP_PROVIDERS:Array<any>',
'const BROWSER_PROVIDERS:Array<any>',
'const ELEMENT_PROBE_BINDINGS:any',
'const ELEMENT_PROBE_PROVIDERS:any[]',
'const ELEMENT_PROBE_PROVIDERS_PROD_MODE:any[]',
'disableDebugTools():void',
'enableDebugTools(ref:ComponentRef):void',
'inspectNativeElement(element:any):DebugElement'
'inspectNativeElement(element:any):DebugNode'
];
describe('public API', () => {