From d2b0b64b9f4447bc6aab4453b7d3b0afe853a4af Mon Sep 17 00:00:00 2001 From: Alessandro Gimona Date: Fri, 22 Nov 2024 06:25:52 +0100 Subject: [PATCH] add v2 test - should update elements correctly --- .../qwik/src/core/tests/use-resource.spec.tsx | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/packages/qwik/src/core/tests/use-resource.spec.tsx b/packages/qwik/src/core/tests/use-resource.spec.tsx index 9b67131dfbe..707e40bba77 100644 --- a/packages/qwik/src/core/tests/use-resource.spec.tsx +++ b/packages/qwik/src/core/tests/use-resource.spec.tsx @@ -339,4 +339,98 @@ describe.each([ ); }); + + it('should update elements correctly', async () => { + (global as any).delay = () => new Promise((res) => ((global as any).delay.resolve = res)); + const ResourceCmp = component$(() => { + const count = useSignal(0); + const resource = useResource$(async ({ track }) => { + track(count); + return count.value + 10; + }); + + return ( + <> + +

Loading..

} + onRejected={() =>

error ...

} + onResolved={(data) => ( + <> +
{data}
+ + + )} + /> + + ); + }); + + const { vNode, container } = await render(, { debug }); + expect(vNode).toMatchVDOM( + + + + + + + +
10
+ +
+
+
+
+
+
+ ); + await trigger(container.element, 'button', 'click'); + + expect(vNode).toMatchVDOM( + + + + + + + +
11
+ +
+
+
+
+
+
+ ); + // await (global as any).delay.resolve(); + await getTestPlatform().flush(); + + expect(vNode).toMatchVDOM( + + + + + + + +
11
+ +
+
+
+
+
+
+ ); + (global as any).delay = undefined; + }); });