@bigbinary/neeto-playwright-commons 1.22.30 → 1.22.32

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/index.d.ts CHANGED
@@ -45,6 +45,15 @@ interface AssertCardDetailsProps {
45
45
  title: string;
46
46
  description: string;
47
47
  }
48
+ type ErrorHandlingResult<T> = {
49
+ success: true;
50
+ result: T;
51
+ };
52
+ type ErrorHandlingFailure = {
53
+ success: false;
54
+ error: string;
55
+ };
56
+ type ErrorHandlingResponse<T> = ErrorHandlingResult<T> | ErrorHandlingFailure;
48
57
  interface VerifyHelpPopoverProps {
49
58
  triggerElement?: Locator;
50
59
  title?: string;
@@ -638,6 +647,36 @@ declare class CustomCommands {
638
647
  title,
639
648
  description
640
649
  }: AssertCardDetailsProps) => Promise<[void, void, void]>;
650
+ /**
651
+ *
652
+ * Method to execute an asynchronous function and safely handle any exceptions that occur. This method provides a simple and type-safe way to handle errors in tests by returning a result object that indicates success or failure.
653
+ *
654
+ * asyncFn: The asynchronous function to execute.
655
+ *
656
+ * Promise<ErrorHandlingResponse<T>> - A result object with either:
657
+ *
658
+ * { success: true, result: T } - When the function executes successfully
659
+ *
660
+ * { success: false, error: string } - When an error occurs
661
+ *
662
+ * @example
663
+ *
664
+ * const userResult = await neetoPlaywrightUtilities.executeWithErrorHandling(async (): Promise<UserData> => {
665
+ * const response = await page.evaluate(() => {
666
+ * return fetch('/api/v1/user').then(r => r.json());
667
+ * });
668
+ *
669
+ * return response;
670
+ * });
671
+ *
672
+ * if (userResult.success === true) {
673
+ * expect(userResult.result.name).toBeTruthy();
674
+ * } else {
675
+ * console.error("Failed to fetch user data:", userResult.error);
676
+ * }
677
+ * @endexample
678
+ */
679
+ executeWithErrorHandling: <T>(asyncFn: () => Promise<T>) => Promise<ErrorHandlingResponse<T>>;
641
680
  /**
642
681
  *
643
682
  * Method to click a button and wait for any loading spinners to disappear.