diff --git a/detox/detox.d.ts b/detox/detox.d.ts index 6adc73128e..2ef5483ea2 100644 --- a/detox/detox.d.ts +++ b/detox/detox.d.ts @@ -1279,12 +1279,31 @@ declare global { * Performs the action repeatedly on the element until an expectation is met * @example await waitFor(element(by.text('Item #5'))).toBeVisible().whileElement(by.id('itemsList')).scroll(50, 'down'); */ - whileElement(by: NativeMatcher): NativeElement & WaitFor; + whileElement(by: NativeMatcher): NativeElementWaitableActions & WaitFor; // TODO: not sure about & WaitFor - check if we can chain whileElement multiple times } - interface NativeElementActions { + interface NativeElementWaitableActions { + + /** + * Scrolls a given amount of pixels in the provided direction, starting from the provided start positions. + * @param pixels - independent device pixels + * @param direction - left/right/up/down + * @param startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically + * @param startPositionY - the Y starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically + * @example await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85); + * @example await element(by.id('scrollView')).scroll(100, 'up'); + */ + scroll( + pixels: number, + direction: Direction, + startPositionX?: number, + startPositionY?: number + ): Promise; + } + + interface NativeElementActions extends NativeElementWaitableActions{ /** * Simulate tap on an element * @param point relative coordinates to the matched element (the element size could changes on different devices or even when changing the device font size) @@ -1352,22 +1371,6 @@ declare global { */ tapReturnKey(): Promise; - /** - * Scrolls a given amount of pixels in the provided direction, starting from the provided start positions. - * @param pixels - independent device pixels - * @param direction - left/right/up/down - * @param startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically - * @param startPositionY - the Y starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically - * @example await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85); - * @example await element(by.id('scrollView')).scroll(100, 'up'); - */ - scroll( - pixels: number, - direction: Direction, - startPositionX?: number, - startPositionY?: number - ): Promise; - /** * Scroll to index. * @example await element(by.id('scrollView')).scrollToIndex(10); diff --git a/detox/test/types/detox-global-tests.ts b/detox/test/types/detox-global-tests.ts index 293cf930cd..efb86e0cb8 100644 --- a/detox/test/types/detox-global-tests.ts +++ b/detox/test/types/detox-global-tests.ts @@ -92,6 +92,14 @@ describe("Test", () => { .whileElement(by.id("ScrollView630")) .scroll(50, "down"); + await waitFor(element(by.text("Text5"))) + .toBeVisible() + .whileElement(by.id("ScrollView630")) + .scroll(50, "down", 0.5, 0.5); + + // @ts-expect-error + await waitFor(element(by.text("Text5"))).toBeVisible().whileElement(by.id("ScrollView630")).tap(); + await web.element(by.web.id("btnSave")).tap(); await web.element(by.web.id("btnSave")).runScript('(el) => el.click()'); const scriptResult = await web.element(by.web.id("btnSave")).runScript(function (el: any, text: string) {