Skip to content

Commit 92727a2

Browse files
committed
chore: add e2e route loaders serialization test
1 parent b0e9c6b commit 92727a2

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

starters/apps/qwikrouter-test/src/routes/loaders-serialization/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export default component$(() => {
1818
return (
1919
<>
2020
{testSignal.value.test}
21-
<button onClick$={() => (toggle.value = !toggle.value)}>
21+
<button id="toggle-child" onClick$={() => (toggle.value = !toggle.value)}>
2222
toggle child
2323
</button>
2424
{toggle.value && <Child />}
25-
<ChildEager />
25+
{toggle.value && <ChildEager />}
2626
</>
2727
);
2828
});
@@ -41,8 +41,8 @@ export const ChildEager = component$(() => {
4141
const testSignal = useTestLoaderEager();
4242
return (
4343
<>
44-
<div id="prop1">{testSignal.value.foo}</div>
45-
<div id="prop2">{testSignal.value.bar}</div>
44+
<div id="prop3">{testSignal.value.foo}</div>
45+
<div id="prop4">{testSignal.value.bar}</div>
4646
</>
4747
);
4848
});

starters/e2e/qwikrouter/loaders.e2e.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,34 @@ test.describe("loaders", () => {
151151
const body = page.locator("body");
152152
await expect(body).toContainText("server-error-data");
153153
});
154+
155+
test("should not serialize loaders by default and serialize with serializationStrategy: always", async ({
156+
page,
157+
javaScriptEnabled,
158+
}) => {
159+
await page.goto("/qwikrouter-test/loaders-serialization/");
160+
const stateData = page.locator('script[type="qwik/state"]');
161+
162+
expect(await stateData.textContent()).not.toContain("some test value");
163+
expect(await stateData.textContent()).not.toContain(
164+
"should not serialize this",
165+
);
166+
expect(await stateData.textContent()).toContain("some eager test value");
167+
expect(await stateData.textContent()).toContain("should serialize this");
168+
169+
if (javaScriptEnabled) {
170+
await page.locator("#toggle-child").click();
171+
await expect(page.locator("#prop1")).toHaveText("some test value");
172+
await expect(page.locator("#prop2")).toHaveText(
173+
"should not serialize this",
174+
);
175+
await expect(page.locator("#prop3")).toHaveText(
176+
"some eager test value",
177+
);
178+
await expect(page.locator("#prop4")).toHaveText(
179+
"should serialize this",
180+
);
181+
}
182+
});
154183
}
155184
});

0 commit comments

Comments
 (0)