Reputation: 6326
Is there any way in which I could test say the height
css property of an element?
I have a function that changes the height of a div
and it would be nice to check in the tests that the function operates correctly...
ie:
<div #myDiv>Hello world</div>
@ViewChild('myDiv') myDiv: ElementRef;
myFunct() {
this.myDiv.nativeElement.style.height = 500;
}
it('should increase div size', () => {
// Here is where I get stuck...
});
Implementing a test such as:
it('should return correct height of dropdown when initialised', () => {
component.myFunct();
expect(component.dropdown.nativeElement.style.height).toBe(34);
});
results in a test failure with message:
Expected '' to be 500.
Upvotes: 3
Views: 6886
Reputation: 540
Something like this...
Exposed the myDiv publicly
Setup the testbed for the component (usually added by default)
Add
component.myFunct(); expect(component.myDiv.nativeElement.style.height).toBe(500);
Upvotes: 6