From 0ed9c9543c57f7b70a560372456ea7567f98dff8 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 13 Jun 2022 09:22:55 +0200 Subject: [PATCH] test(cdk/testing): use offsetX and offsetY to verify element coordinates 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 f74c449c086d19c6d70c64a88146ea0393beb586) --- src/cdk/testing/tests/test-main-component.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cdk/testing/tests/test-main-component.ts b/src/cdk/testing/tests/test-main-component.ts index 4121e0c33341..cb28eb951f16 100644 --- a/src/cdk/testing/tests/test-main-component.ts +++ b/src/cdk/testing/tests/test-main-component.ts @@ -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); } }