Component unit test: By.css() does not match when in SVG namespace : <p>In short, I'm looking for a way to make the predicate <code>By.css([css-selector])</code> (see <a href="https://angular.io/docs/ts/latest/api/platform-browser/index/By-class.html">https://angular.io/docs/ts/latest/api/platform-browser/index/By-class.html</a>) work in Angular2 (v2.0.1+) component unit tests when a namespace (SVG) is involved.</p>

<p>(The related predicates <code>By.all()</code> and <code>By.directive(DirectiveClass)</code> work fine.)</p>

<p>Below is a self-contained spec to demonstrate the issue.  The result is</p>

<pre><code>DivComponent class specs:
    ✔ NG should evaluate component and template.
    ✔ Div should be locatable by tag.
    ✔ Div should be locatable by id.
    ✔ Div should be locatable by class.
    ✔ Match should fail a negative.
ShapesComponent class specs:
    ✔ NG should evaluate the component and template.
    ✖ Circle should be locatable by tag.
    ✖ Circle should be locatable by ns:tag.
    ✖ Circle should be locatable by id.
    ✖ Circle should be locatable by class.
</code></pre>

<p>Spec:</p>

<pre><code>import {TestBed, ComponentFixture} from '@angular/core/testing';
import {Component, DebugElement} from '@angular/core';
import {By} from '@angular/platform-browser';

/*
 * A simple component in HTML namespace
 */
@Component({
    selector: '[app-div]',
    template: '&lt;div class="myDivClass" id="myDivId"&gt;Hello World&lt;/div&gt;'
})
export class DivComponent {
}

/*
 * A simple component in SVG namespace
 */
@Component({
    selector: '[app-shape]',
    template: '&lt;svg:circle class="myCircleClass" id="myCircleId" ' +
    'cx="80" cy="80" r="20"&gt;&lt;/svg:circle&gt;'
})
export class ShapesComponent {
}

function dumpElements(elements: DebugElement[]) {
    console.log('Matcher found ' + elements.length + ' elements.');
    for (let i = 0; i &lt; elements.length; i++) {
        console.log('element[' + i + '] = '
            + elements[i].nativeElement.tagName
            + ': ' + elements[i].nativeElement.outerHTML);
    }
}

/* 
 * Test "By.css()" on the DivComponent.
 */
describe('DivComponent class specs:', () =&gt; {

    let divComponent: DivComponent;
    let fixture: ComponentFixture&lt;DivComponent&gt;;
    let de: DebugElement;

    beforeEach(() =&gt; {
        TestBed.configureTestingModule({
            declarations: [
                DivComponent
            ]
        });
        TestBed.compileComponents();
        fixture = TestBed.createComponent(DivComponent);
        fixture.detectChanges();
        de = fixture.debugElement;
    });

    it('NG should evaluate component and template.', () =&gt; {
        // Dump elements if needed:
        // dumpElements(de.queryAll(By.all()));
        expect(de.queryAll(By.all()).length).toBe(1);
    });
    it('Div should be locatable by tag.', () =&gt; {
        expect(de.queryAll(By.css('div')).length).toBe(1);
    });
    it('Div should be locatable by id.', () =&gt; {
        expect(de.queryAll(By.css('#myDivId')).length).toBe(1);
    });
    it('Div should be locatable by class.', () =&gt; {
        expect(de.queryAll(By.css('.myDivClass')).length).toBe(1);
    });
    it('Match should fail a negative.', () =&gt; {
        expect(de.queryAll(By.css('#negative')).length).toBe(0);
    });
});

/* 
 * Use the same "By.css()" syntax on the ShapeComponent.
 */
describe('ShapesComponent class specs:', () =&gt; {

    let divComponent: ShapesComponent;
    let fixture: ComponentFixture&lt;ShapesComponent&gt;;
    let de: DebugElement;

    beforeEach(() =&gt; {
        TestBed.configureTestingModule({
            declarations: [
                ShapesComponent
            ]
        });
        TestBed.compileComponents();
        fixture = TestBed.createComponent(ShapesComponent);
        fixture.detectChanges();
        de = fixture.debugElement;
    });

    it('NG should evaluate the component and template.', () =&gt; {
        // Dump elements if needed:
        // dumpElements(de.queryAll(By.all()));
        expect(de.queryAll(By.all()).length).toBe(1); // pass
    });

    it('Circle should be locatable by tag.', () =&gt; {
        expect(de.queryAll(By.css('circle')).length).toBe(1);
    });
    it('Circle should be locatable by ns:tag.', () =&gt; {
        expect(de.queryAll(By.css('svg:circle')).length).toBe(1);
    });
    it('Circle should be locatable by id.', () =&gt; {
        expect(de.queryAll(By.css('#myCircleId')).length).toBe(1);
    });
    it('Circle should be locatable by class.', () =&gt; {
        expect(de.queryAll(By.css('.myCircleClass')).length).toBe(1);
    });
});
</code></pre>
