Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add v2 test - should update elements correctly #7085

Open
wants to merge 1 commit into
base: build/v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions packages/qwik/src/core/tests/use-resource.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,98 @@
</Component>
);
});

it('should update elements correctly', async () => {
(global as any).delay = () => new Promise<void>((res) => ((global as any).delay.resolve = res));
const ResourceCmp = component$(() => {
const count = useSignal(0);
const resource = useResource$<number>(async ({ track }) => {
track(count);
return count.value + 10;
});

return (
<>
<button onClick$={() => count.value++}>{count.value}</button>
<Resource
value={resource}
// uncomment to test pending WORKING and test pass
// onPending={() => <p>Loading..</p>}
onRejected={() => <p>error ...</p>}
onResolved={(data) => (
<>
<div>{data}</div>
<input value={`${data}`} />
</>
)}
/>
</>
);
});

const { vNode, container } = await render(<ResourceCmp />, { debug });
expect(vNode).toMatchVDOM(

Check failure on line 372 in packages/qwik/src/core/tests/use-resource.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/tests/use-resource.spec.tsx > 'domRender': useResource > should update elements correctly

Error: Fragment > Fragment > Fragment > Fragment > Fragment > Fragment > input: [value] EXPECTED: "10" RECEIVED: "undefined" ❯ qwik/src/core/tests/use-resource.spec.tsx:372:19
<Component ssr-required>
<Fragment ssr-required>
<button>
<Signal ssr-required>0</Signal>
</button>
<InlineComponent ssr-required>
<Fragment ssr-required>
<Awaited ssr-required>
<Fragment ssr-required>
<div>10</div>
<input value="10" />
</Fragment>
</Awaited>
</Fragment>
</InlineComponent>
</Fragment>
</Component>
);
await trigger(container.element, 'button', 'click');

expect(vNode).toMatchVDOM(

Check failure on line 393 in packages/qwik/src/core/tests/use-resource.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/tests/use-resource.spec.tsx > 'ssrRenderToDom': useResource > should update elements correctly

Error: Fragment > Fragment > Fragment > Fragment > Fragment > Fragment > input: [value] EXPECTED: "11" RECEIVED: "10" ❯ qwik/src/core/tests/use-resource.spec.tsx:393:19
<Component ssr-required>
<Fragment ssr-required>
<button>
<Signal ssr-required>1</Signal>
</button>
<InlineComponent ssr-required>
<Fragment ssr-required>
<Awaited ssr-required>
<Fragment ssr-required>
<div>11</div>
<input value="11" />
</Fragment>
</Awaited>
</Fragment>
</InlineComponent>
</Fragment>
</Component>
);
// await (global as any).delay.resolve();
await getTestPlatform().flush();

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<button>
<Signal ssr-required>1</Signal>
</button>
<InlineComponent ssr-required>
<Fragment ssr-required>
<Awaited ssr-required>
<Fragment ssr-required>
<div>11</div>
<input value="11" />
</Fragment>
</Awaited>
</Fragment>
</InlineComponent>
</Fragment>
</Component>
);
(global as any).delay = undefined;
});
});
Loading