Skip to content

Commit 7e4d6cb

Browse files
committed
Add unit tests for fixUint8Array
1 parent 5412f75 commit 7e4d6cb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { fixUint8Array } from "./uint8array";
2+
3+
describe("fixUint8Array", () => {
4+
it("works for Uint8Array<ArrayBuffer>", () => {
5+
const input: Uint8Array<ArrayBuffer> = Uint8Array.of(1, 2, 255);
6+
const fixed = fixUint8Array(input);
7+
expect(fixed).toEqual(input);
8+
expect(fixed.buffer).toBeInstanceOf(ArrayBuffer);
9+
expect(fixed.buffer).toBe(input.buffer); // no copy must be performed in this case
10+
});
11+
12+
it("works for Uint8Array<SharedArrayBuffer>", () => {
13+
const sharedBuffer = new SharedArrayBuffer(8);
14+
const input: Uint8Array<SharedArrayBuffer> = new Uint8Array(sharedBuffer);
15+
const fixed = fixUint8Array(input);
16+
expect(fixed).toEqual(input);
17+
expect(fixed.buffer).toBeInstanceOf(ArrayBuffer);
18+
});
19+
});

0 commit comments

Comments
 (0)