From 4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 9 Jan 2023 20:20:09 -0300 Subject: fix #7153: more error handling if handler do not trap error then fail at compile time, all safe handlers push alert on error errors are typed so they render good information --- .../src/hooks/useTalerActionURL.test.ts | 56 ++++++++++------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts') diff --git a/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts b/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts index 8aabb8adf..e70f7f9be 100644 --- a/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts +++ b/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts @@ -13,11 +13,11 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { useTalerActionURL } from "./useTalerActionURL.js"; -import { mountHook } from "../test-utils.js"; -import { IoCProviderForTesting } from "../context/iocContext.js"; -import { h, VNode } from "preact"; import { expect } from "chai"; +import { h, VNode } from "preact"; +import { IoCProviderForTesting } from "../context/iocContext.js"; +import { useTalerActionURL } from "./useTalerActionURL.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; describe("useTalerActionURL hook", () => { it("should be set url to undefined when dismiss", async () => { @@ -31,32 +31,28 @@ describe("useTalerActionURL hook", () => { }); }; - const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(useTalerActionURL, ctx); - - { - const [url] = pullLastResultOrThrow(); - expect(url).undefined; - } - - expect(await waitForStateUpdate()).true; - - { - const [url, setDismissed] = pullLastResultOrThrow(); - expect(url).deep.equals({ - location: "clipboard", - uri: "qwe", - }); - setDismissed(true); - } - - expect(await waitForStateUpdate()).true; + const hookBehavior = await tests.hookBehaveLikeThis( + useTalerActionURL, + {}, + [ + ([url]) => { + expect(url).undefined; + }, + ([url, setDismissed]) => { + expect(url).deep.equals({ + location: "clipboard", + uri: "qwe", + }); + setDismissed(true); + }, + ([url]) => { + if (url !== undefined) throw Error("invalid"); + expect(url).undefined; + }, + ], + ctx, + ); - { - const [url] = pullLastResultOrThrow(); - if (url !== undefined) throw Error("invalid"); - expect(url).undefined; - } - await assertNoPendingUpdate(); + expect(hookBehavior).deep.equal({ result: "ok" }); }); }); -- cgit v1.2.3