twd-js 1.6.6 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -288,7 +288,7 @@ declare interface TWDAPI {
288
288
  /**
289
289
  * Mock a network request.
290
290
  *
291
- * @param alias Identifier for the mock rule. Useful for `waitFor()`.
291
+ * @param alias Identifier for the mock rule. Useful for `waitForRequest()`.
292
292
  * @param options Options to configure the mock:
293
293
  * - `method`: HTTP method ("GET", "POST", …)
294
294
  * - `url`: URL string or RegExp to match
@@ -318,9 +318,9 @@ declare interface TWDAPI {
318
318
  *
319
319
  * @example
320
320
  * ```ts
321
- * const rule = await twd.waitFor("aliasId");
321
+ * const rule = await twd.waitForRequest("aliasId");
322
322
  * console.log(rule.body);
323
- * const rule = await twd.waitFor("aliasId", 5, 100);
323
+ * const rule = await twd.waitForRequest("aliasId", 5, 100);
324
324
  * console.log(rule.body);
325
325
  *
326
326
  * ```
@@ -412,6 +412,33 @@ declare interface TWDAPI {
412
412
  * ```
413
413
  */
414
414
  wait: (time: number) => Promise<void>;
415
+ /**
416
+ * Retries a callback until it stops throwing or the timeout expires.
417
+ * Use this instead of `twd.wait(ms)` to wait for conditions rather than fixed delays.
418
+ *
419
+ * @param callback Function to retry — can be sync or async. Should throw if the condition is not yet met.
420
+ * @param options Optional timeout, interval, and message settings
421
+ * @returns A promise that resolves with the callback's return value when it succeeds
422
+ *
423
+ * @example
424
+ * ```ts
425
+ * // Wait for an analytics event and return it
426
+ * const event = await twd.waitFor(() => {
427
+ * const ev = findEvent("purchase");
428
+ * expect(ev).to.exist;
429
+ * return ev;
430
+ * }, { message: "purchase event to fire" });
431
+ *
432
+ * // Wait for an element (single expression)
433
+ * const heading = await twd.waitFor(() => screenDom.getByRole("heading", { name: /checkout/i }));
434
+ *
435
+ * // Fire-and-forget (void) — still works as before
436
+ * await twd.waitFor(() => {
437
+ * expect(submitButton.disabled).to.be.false;
438
+ * });
439
+ * ```
440
+ */
441
+ waitFor: <T>(callback: () => T | Promise<T>, options?: WaitForOptions) => Promise<T>;
415
442
  /**
416
443
  * Asserts something about the element.
417
444
  * @param el The element to assert on
@@ -622,4 +649,16 @@ declare type UserEvent = typeof default_2;
622
649
 
623
650
  export declare const userEvent: UserEvent;
624
651
 
652
+ /**
653
+ * Options for `twd.waitFor()`.
654
+ */
655
+ declare interface WaitForOptions {
656
+ /** Max time to wait in ms. Default: 2000 */
657
+ timeout?: number;
658
+ /** Poll interval in ms. Default: 50 */
659
+ interval?: number;
660
+ /** Context message included in timeout errors */
661
+ message?: string;
662
+ }
663
+
625
664
  export { }