(value: unknown)
| 2747 | // This helper function extracts the result of `stringify` by triggering an `UnhandledEffectError` |
| 2748 | // and extracting the formatted payload from the error message |
| 2749 | function stringify(value: unknown): string { |
| 2750 | // Create an effect with our test value as its payload |
| 2751 | const testStringify = effect("testStringify")<[value: unknown], void>; |
| 2752 | |
| 2753 | try { |
| 2754 | // Running this will throw an `UnhandledEffectError` with our value stringified in the message |
| 2755 | effected(function* () { |
| 2756 | yield* testStringify(value); |
| 2757 | }).runSyncUnsafe(); |
| 2758 | throw new Error("Expected UnhandledEffectError to be thrown"); |
| 2759 | } catch (error) { |
| 2760 | if (!(error instanceof UnhandledEffectError)) { |
| 2761 | throw error; |
| 2762 | } |
| 2763 | |
| 2764 | // Extract just the stringified part from: "Unhandled effect: testStringify(<stringified value>)" |
| 2765 | return error.message.replace("Unhandled effect: testStringify(", "").slice(0, -1); |
| 2766 | } |
| 2767 | } |
| 2768 | |
| 2769 | it("should handle primitive values correctly", () => { |
| 2770 | expect(stringify(42)).toBe("42"); |
no test coverage detected