Skip to content
Permalink
Browse files

fix(ivy): get name directly from nativeNode (#32198)

nativeElement can return null so an error can occur when accessing
nodeName from nativeElement.

PR Close #32198
  • Loading branch information...
atscott authored and AndrewKushnir committed Aug 19, 2019
1 parent cfed0c0 commit 3dbc4ab572023fbf254dfc41c222fe54c70a7155
Showing with 19 additions and 1 deletion.
  1. +1 −1 packages/core/src/debug/debug_node.ts
  2. +18 −0 packages/core/test/debug/debug_node_spec.ts
@@ -247,7 +247,7 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
return this.nativeNode.nodeType == Node.ELEMENT_NODE ? this.nativeNode as Element : null;
}

get name(): string { return this.nativeElement !.nodeName; }
get name(): string { return this.nativeNode.nodeName; }

/**
* Gets a map of property names to property values for an element.
@@ -1018,4 +1018,22 @@ class TestCmptWithPropBindings {
});

});

it('should not error when accessing node name', () => {
@Component({template: ''})
class EmptyComponent {
}

const fixture = TestBed.configureTestingModule({declarations: [EmptyComponent]})
.createComponent(EmptyComponent);
let node = fixture.debugElement;
let superParentName = '';
// Traverse upwards, all the way to #document, which is not a
// Node.ELEMENT_NODE
while (node) {
superParentName = node.name;
node = node.parent !;
}
expect(superParentName).not.toEqual('');
});
}

0 comments on commit 3dbc4ab

Please sign in to comment.
You can’t perform that action at this time.