Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of span tag in jasmine angular2 testing

Here is my html code

<span class="boxText">
            {{model.number}}
    <i *ngIf="model.canText" class="fa fa-comment" placement="right"></i>
</span>

There is only one span tag in my code. I want to test if span tag contains the specific value, i.e model.number.

Here I am able to get the span element.

let el = fixture.debugElement.query(By.css('.boxText'));
let spanEl = el.nativeElement; 

But not able check if the value exist. How do i do this using jasmine?

like image 568
Amit Chigadani Avatar asked Dec 04 '22 22:12

Amit Chigadani


1 Answers

I leave here the answer for someone else, but it was just accessing the element as on plain js.

let el = fixture.debugElement.query(By.css('.boxText'));
let spanEl = el.nativeElement;
// spanEl.innerHTML => give you the value

and test like normally

expect(spanEl.innerHTML).toContain(component.model.number);
like image 162
Alejandro Lora Avatar answered Dec 11 '22 15:12

Alejandro Lora