diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-01 14:37:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 14:37:46 +0200 |
commit | 29db4104c4b05d7eff3a5d74514db0904ea1cd98 (patch) | |
tree | ca916fd13f3f856cde0b3a41476e3e022503a272 /cli/tests/unit/fetch_test.ts | |
parent | 1d3dce9a68c981aded31b4eb12f8a2ec4beecfab (diff) |
fix(cli/web): Body.bodyUsed should use IsReadableStreamDisturbed
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 57414d652..554cf31e9 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -100,6 +100,39 @@ unitTest({ perms: { net: true } }, async function fetchBodyUsed(): Promise< assertEquals(response.bodyUsed, true); }); +unitTest( + { perms: { net: true } }, + async function fetchBodyUsedReader(): Promise<void> { + const response = await fetch( + "http://localhost:4545/cli/tests/fixture.json" + ); + assert(response.body !== null); + + const reader = response.body.getReader(); + // Getting a reader should lock the stream but does not consume the body + // so bodyUsed should not be true + assertEquals(response.bodyUsed, false); + reader.releaseLock(); + await response.json(); + assertEquals(response.bodyUsed, true); + } +); + +unitTest( + { perms: { net: true } }, + async function fetchBodyUsedCancelStream(): Promise<void> { + const response = await fetch( + "http://localhost:4545/cli/tests/fixture.json" + ); + assert(response.body !== null); + + assertEquals(response.bodyUsed, false); + const promise = response.body.cancel(); + assertEquals(response.bodyUsed, true); + await promise; + } +); + unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< void > { |