Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elia872 committed Aug 11, 2023
1 parent e133aba commit d81597e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export async function load({ fetch }) {
const res = await fetch('/load/fetch-arraybuffer-b64/data');

return {
data: res.arrayBuffer()
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
export let data;
$: arr = [...new Uint8Array(data.data)];
</script>

<span class="test-content">{JSON.stringify(arr)}</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const GET = () => {
return new Response(new Uint8Array([1, 2, 3, 4]));
};
16 changes: 16 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ test.describe('Load', () => {
}
});

test('fetches using an arraybuffer serialized with b64', async ({ page, javaScriptEnabled }) => {
await page.goto('/load/fetch-arraybuffer-b64');

expect(await page.textContent('.test-content')).toBe('[1,2,3,4]');

if (!javaScriptEnabled) {
const payload = '{"status":200,"statusText":"","headers":{},"body":"AQIDBA=="}';

const script_content = await page.innerHTML(
'script[data-sveltekit-fetched][data-b64][data-url="/load/fetch-arraybuffer-b64/data"]'
);

expect(script_content).toBe(payload);
}
});

test('json string is returned', async ({ page }) => {
await page.goto('/load/relay');
expect(await page.textContent('h1')).toBe('42');
Expand Down

0 comments on commit d81597e

Please sign in to comment.