mercredi 18 novembre 2015

Angular 2 unit testing unable to test nested components

I've start with the ng2-test-seed developed by @Jmr with the angular team. It can be found here:ng2-test-seed

So, I've setup the component like so

@Component({
selector: "my-text",
inputs: ['config'],
template: `
    <my-label>
        <p>{{config.value}}</p>
    </my-label>
`,
directives: [LabelComponent]
})
export class TextComponent implements Control {
    constructor() { }
}

my-label uses ng-content to display the "p" element.

Then I run my test...

.createAsync(TestComponent).then((fixture) => {
    fixture.detectChanges();
    var compiled = fixture.debugElement.nativeElement;
    expect(compiled.querySelectorAll("p")[0].innerHTML).toEqual("Blah");
});

I try to grab the "p" element but it does not seem to be available in the DOM yet.

Is there some option/setting you have to set in the test harness to get the nested elements?

I've tried to get the children but the element is no where to be found at the time the test runs, yet in the debug window the component appears as expected after the fact.

Aucun commentaire:

Enregistrer un commentaire