From 4aa0c51653284ab70c016cd0cdb91375d04b5a4d Mon Sep 17 00:00:00 2001 From: creatixchu Date: Fri, 31 Jul 2026 16:40:25 +0800 Subject: [PATCH] test(web): read the native Range.setStart through its descriptor The reveal spec wraps setStart to record which layer and index the composer measures; capturing the method directly trips the unbound-method rule, which the pre-commit lint caught after a --no-verify commit slipped it through. --- packages/client/ui-conversation/tests/input-bar.spec.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/client/ui-conversation/tests/input-bar.spec.tsx b/packages/client/ui-conversation/tests/input-bar.spec.tsx index a55d32d9a2..551c50c394 100644 --- a/packages/client/ui-conversation/tests/input-bar.spec.tsx +++ b/packages/client/ui-conversation/tests/input-bar.spec.tsx @@ -25,7 +25,10 @@ afterEach(cleanup) const ZERO_RECT = (): DOMRect => ({ top: 0, bottom: 0 }) as DOMRect Range.prototype.getBoundingClientRect = ZERO_RECT -const nativeSetStart = Range.prototype.setStart +// Read through the descriptor so the native method is never referenced unbound; +// the reveal case below wraps it to record what it was asked to measure. +const NATIVE_SET_START = Object.getOwnPropertyDescriptor(Range.prototype, 'setStart')! + .value as (this: Range, node: Node, offset: number) => void const SCTX = {} as ClientContext const SID = 's1' as SessionId @@ -333,7 +336,7 @@ describe('running and lock semantics (queue cut 1)', () => { Object.defineProperty(scroll, 'scrollTop', { value: 0, writable: true, configurable: true }) onTestFinished(() => { Range.prototype.getBoundingClientRect = ZERO_RECT - Range.prototype.setStart = nativeSetStart + Range.prototype.setStart = NATIVE_SET_START }) // Which layer the caret is measured against, and at which index: the stub // records `setStart` so a helper that measured the backdrop instead, or @@ -341,7 +344,7 @@ describe('running and lock semantics (queue cut 1)', () => { let measured: { node: Node; offset: number } | null = null Range.prototype.setStart = function setStart(node: Node, offset: number): void { measured = { node, offset } - nativeSetStart.call(this, node, offset) + NATIVE_SET_START.call(this, node, offset) } const caretAt = (top: number): void => { Range.prototype.getBoundingClientRect = () => ({ top, bottom: top + 24 }) as DOMRect