twd-js 1.6.6 → 1.7.0
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/bundled.es.js +1 -1
- package/dist/index.cjs.js +32 -31
- package/dist/index.d.ts +39 -3
- package/dist/index.es.js +873 -848
- package/dist/mock-sw.js +1 -1
- package/package.json +6 -6
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 `
|
|
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.
|
|
321
|
+
* const rule = await twd.waitForRequest("aliasId");
|
|
322
322
|
* console.log(rule.body);
|
|
323
|
-
* const rule = await twd.
|
|
323
|
+
* const rule = await twd.waitForRequest("aliasId", 5, 100);
|
|
324
324
|
* console.log(rule.body);
|
|
325
325
|
*
|
|
326
326
|
* ```
|
|
@@ -412,6 +412,30 @@ 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 when the callback succeeds
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* // Wait for an analytics event
|
|
426
|
+
* await twd.waitFor(() => {
|
|
427
|
+
* const event = findEvent("purchase");
|
|
428
|
+
* expect(event).to.exist;
|
|
429
|
+
* }, { message: "purchase event to fire" });
|
|
430
|
+
*
|
|
431
|
+
* // Wait with custom timeout
|
|
432
|
+
* await twd.waitFor(() => {
|
|
433
|
+
* const el = document.querySelector(".loaded");
|
|
434
|
+
* if (!el) throw new Error("not loaded");
|
|
435
|
+
* }, { timeout: 5000 });
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
waitFor: (callback: () => void | Promise<void>, options?: WaitForOptions) => Promise<void>;
|
|
415
439
|
/**
|
|
416
440
|
* Asserts something about the element.
|
|
417
441
|
* @param el The element to assert on
|
|
@@ -622,4 +646,16 @@ declare type UserEvent = typeof default_2;
|
|
|
622
646
|
|
|
623
647
|
export declare const userEvent: UserEvent;
|
|
624
648
|
|
|
649
|
+
/**
|
|
650
|
+
* Options for `twd.waitFor()`.
|
|
651
|
+
*/
|
|
652
|
+
declare interface WaitForOptions {
|
|
653
|
+
/** Max time to wait in ms. Default: 2000 */
|
|
654
|
+
timeout?: number;
|
|
655
|
+
/** Poll interval in ms. Default: 50 */
|
|
656
|
+
interval?: number;
|
|
657
|
+
/** Context message included in timeout errors */
|
|
658
|
+
message?: string;
|
|
659
|
+
}
|
|
660
|
+
|
|
625
661
|
export { }
|