Skip to content

Commit

Permalink
test(cdk/testing): use offsetX and offsetY to verify element coordinates
Browse files Browse the repository at this point in the history
Currently a couple of the tests use `clientX` and `clientY` plus the element's `ClientRect` to verify click coordinates relative to an element. This can cause flakes in tests, because the `ClientRect` changes depending on the page's scroll position.

These changes use `offsetX` and `offsetY` instead which are actually relative to the element.

(cherry picked from commit f74c449)
  • Loading branch information
crisbeto committed Jun 13, 2022
1 parent 7329690 commit 0ed9c95
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/cdk/testing/tests/test-main-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export class TestMainComponent implements OnDestroy {
}

private _assignRelativeCoordinates(event: MouseEvent, obj: {x: number; y: number}) {
const {top, left} = this.clickTestElement.nativeElement.getBoundingClientRect();
obj.x = Math.round(event.clientX - left);
obj.y = Math.round(event.clientY - top);
obj.x = Math.round(event.offsetX);
obj.y = Math.round(event.offsetY);
}
}

0 comments on commit 0ed9c95

Please sign in to comment.