forked from aws/aws-sdk-js-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream-collector.spec.ts
More file actions
44 lines (39 loc) · 1.29 KB
/
stream-collector.spec.ts
File metadata and controls
44 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { streamCollector } from "./stream-collector";
describe("streamCollector", () => {
it("returns a Uint8Array from a blob", done => {
const dataPromise = new Response(new Uint8Array([102, 111, 111]).buffer)
.blob()
.then(blob => streamCollector(blob));
dataPromise.then((data: any) => {
expect(data).toEqual(Uint8Array.from([102, 111, 111]));
done();
});
});
it("returns a Uint8Array from a ReadableStream", done => {
const dataPromise = streamCollector(
new Response(new Uint8Array([102, 111, 111]).buffer).body
);
dataPromise.then((data: any) => {
expect(data).toEqual(Uint8Array.from([102, 111, 111]));
done();
});
});
it("returns a Uint8Array when stream is empty", done => {
const expected = new Uint8Array(0);
const dataPromise = streamCollector(new Response(expected.buffer).body);
dataPromise.then((data: any) => {
expect(data).toEqual(expected);
done();
});
});
it("returns a Uint8Array when blob is empty", done => {
const expected = new Uint8Array(0);
const dataPromise = new Response(expected.buffer)
.blob()
.then(blob => streamCollector(blob));
dataPromise.then((data: any) => {
expect(data).toEqual(Uint8Array.from([]));
done();
});
});
});