Skip to content

Commit f74c449

Browse files
committed
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.
1 parent 1d15ea7 commit f74c449

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/cdk/testing/tests/test-main-component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ export class TestMainComponent implements OnDestroy {
123123
}
124124

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

0 commit comments

Comments
 (0)