-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbinary-data.test.ts
More file actions
28 lines (21 loc) · 887 Bytes
/
binary-data.test.ts
File metadata and controls
28 lines (21 loc) · 887 Bytes
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
import { describe, expect, it } from 'vitest';
import { readBinaryData } from './binary-data.ts';
describe('readBinaryData', () => {
it('returns original Uint8Array', () => {
const data = Uint8Array.of(1, 183, 0);
expect(readBinaryData(data)).toBe(data);
});
it('throws for ArrayBuffer', () => {
const buffer = Uint8Array.of(1, 183, 0).buffer;
expect(() => readBinaryData(buffer)).toThrow(
new TypeError('Expected Uint8Array, got: ArrayBuffer [1, 183, 0]'),
);
});
it('throws for strings', () => {
expect(() => readBinaryData('AbcA')).toThrow(new TypeError("Expected Uint8Array, got: 'AbcA'"));
});
it('throws for other types', () => {
expect(() => readBinaryData(23)).toThrow(new TypeError('Expected Uint8Array, got: 23'));
expect(() => readBinaryData(null)).toThrow(new TypeError('Expected Uint8Array, got: null'));
});
});