From f45ef767016a425d04cce7755b27aceff292603c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 24 Mar 2022 16:02:38 -0300 Subject: esbuild configuration --- packages/taler-wallet-webextension/src/test-utils.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-webextension/src/test-utils.ts') diff --git a/packages/taler-wallet-webextension/src/test-utils.ts b/packages/taler-wallet-webextension/src/test-utils.ts index 30b37ab8c..24dba8c7b 100644 --- a/packages/taler-wallet-webextension/src/test-utils.ts +++ b/packages/taler-wallet-webextension/src/test-utils.ts @@ -14,10 +14,16 @@ GNU Taler; see the file COPYING. If not, see */ -import { PendingTestFunction, TestFunction } from "mocha"; -import { ComponentChildren, Fragment, FunctionalComponent, h as create, render as renderIntoDom, VNode } from "preact"; +import { ComponentChildren, Fragment, FunctionalComponent, h as create, options, render as renderIntoDom, VNode } from "preact"; import { render as renderToString } from "preact-render-to-string"; +// When doing tests we want the requestAnimationFrame to be as fast as possible. +// without this option the RAF will timeout after 100ms making the tests slower +options.requestAnimationFrame = (fn: () => void) => { + // console.log("RAF called") + return fn() +} + export function createExample( Component: FunctionalComponent, props: Partial, @@ -59,7 +65,7 @@ export function renderNodeOrBrowser(Component: any, args: any): void { interface Mounted { unmount: () => void; result: { current: T | null }; - waitNextUpdate: () => Promise; + waitNextUpdate: (s?: string) => Promise; } const isNode = typeof window === "undefined" @@ -84,10 +90,11 @@ export function mountHook(callback: () => T, Context?: ({ children }: { child const vdom = !Context ? create(Component, {}) : create(Context, { children: [create(Component, {})] },); // waiter callback - async function waitNextUpdate(): Promise { + async function waitNextUpdate(_label = ""): Promise { + if (_label) _label = `. label: "${_label}"` await new Promise((res, rej) => { const tid = setTimeout(() => { - rej(Error("waiting for an update but the hook didn't make one")) + rej(Error(`waiting for an update but the hook didn't make one${_label}`)) }, 100) listener.push(() => { -- cgit v1.2.3