Gets the computed dimension of a DebugElement in pixels.
(el: DebugElement, dimension: 'width' | 'height' | 'top' | 'left')
| 504 | |
| 505 | /** Gets the computed dimension of a DebugElement in pixels. */ |
| 506 | function getDimension(el: DebugElement, dimension: 'width' | 'height' | 'top' | 'left'): number { |
| 507 | const nativeElement: HTMLElement = el.nativeElement; |
| 508 | |
| 509 | switch (dimension) { |
| 510 | // Note that we use direct measurements, rather than the computed style, because |
| 511 | // `getComputedStyle` can be inconsistent between browser and can cause flakes. |
| 512 | case 'width': |
| 513 | return nativeElement.getBoundingClientRect().width; |
| 514 | case 'height': |
| 515 | return nativeElement.getBoundingClientRect().height; |
| 516 | case 'top': |
| 517 | return nativeElement.offsetTop; |
| 518 | case 'left': |
| 519 | return nativeElement.offsetLeft; |
| 520 | default: |
| 521 | throw Error(`Unknown dimension ${dimension}.`); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /** Gets the `left` position of an element. */ |
| 526 | function getComputedLeft(element: DebugElement): number { |
no test coverage detected
searching dependent graphs…