Unit testing css with angular

physicsboy

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...
});

Update

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.

ランス

Something like this...

  1. Exposed the myDiv publicly

  2. Setup the testbed for the component (usually added by default)

  3. Add

component.myFunct();

expect(component.myDiv.nativeElement.style.height).toBe(500);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related