Skip to content

Commit c8bd775

Browse files
committed
Add test for async iterator in endpoint body
1 parent 66bd7a3 commit c8bd775

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/kit/test/apps/basics/src/routes/endpoint-output/_tests.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ export default function (test) {
5656
assert.equal(res.headers.get('content-type'), 'application/xml');
5757
assert.equal(await res.text(), '<foo />');
5858
});
59+
60+
test('gets streaming response from async iterator', null, async ({ fetch }) => {
61+
const res = await fetch('/endpoint-output/async-iterator');
62+
63+
assert.equal(await res.text(), 'foobar');
64+
});
5965
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('@sveltejs/kit').RequestHandler} */
2+
export function get() {
3+
return { body: generateAsyncIterator() };
4+
}
5+
6+
async function* generateAsyncIterator() {
7+
yield 'foo';
8+
yield 'bar';
9+
}

0 commit comments

Comments
 (0)