|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | | -import { parseBinaryData } from './binary-data.ts'; |
| 3 | +import { readBinaryData } from './binary-data.ts'; |
4 | 4 |
|
5 | | -const data = Uint8Array.of(1, 183, 0); |
6 | | - |
7 | | -describe('parseBinaryData', () => { |
| 5 | +describe('readBinaryData', () => { |
8 | 6 | it('returns original Uint8Array', () => { |
9 | | - expect(parseBinaryData(data)).toBe(data); |
10 | | - }); |
| 7 | + const data = Uint8Array.of(1, 183, 0); |
11 | 8 |
|
12 | | - it('returns Uint8Array for ArrayBuffer', () => { |
13 | | - expect(parseBinaryData(data.buffer)).toEqual(data); |
| 9 | + expect(readBinaryData(data)).toBe(data); |
14 | 10 | }); |
15 | 11 |
|
16 | | - it('returns Uint8Array for base64-encoded string', () => { |
17 | | - expect(parseBinaryData('Abc=`')).toEqual(data); |
18 | | - }); |
| 12 | + it('throws for ArrayBuffer', () => { |
| 13 | + const buffer = Uint8Array.of(1, 183, 0).buffer; |
19 | 14 |
|
20 | | - it('returns Uint8Array for data URL', () => { |
21 | | - expect(parseBinaryData('data:image/jpeg;base64,Abc=`')).toEqual(data); |
| 15 | + expect(() => readBinaryData(buffer)).toThrow( |
| 16 | + new TypeError('Expected Uint8Array, got: ArrayBuffer [1, 183, 0]'), |
| 17 | + ); |
22 | 18 | }); |
23 | 19 |
|
24 | | - it('throws for arrays', () => { |
25 | | - expect(() => parseBinaryData([1, 2, 3])).toThrow( |
26 | | - new TypeError('Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: [1, 2, 3]'), |
27 | | - ); |
| 20 | + it('throws for strings', () => { |
| 21 | + expect(() => readBinaryData('AbcA')).toThrow(new TypeError("Expected Uint8Array, got: 'AbcA'")); |
28 | 22 | }); |
29 | 23 |
|
30 | 24 | it('throws for other types', () => { |
31 | | - expect(() => parseBinaryData(23)).toThrow( |
32 | | - new TypeError('Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: 23'), |
33 | | - ); |
34 | | - expect(() => parseBinaryData(null)).toThrow( |
35 | | - new TypeError('Expected Uint8Array, ArrayBuffer, or base64-encoded string, got: null'), |
36 | | - ); |
| 25 | + expect(() => readBinaryData(23)).toThrow(new TypeError('Expected Uint8Array, got: 23')); |
| 26 | + expect(() => readBinaryData(null)).toThrow(new TypeError('Expected Uint8Array, got: null')); |
37 | 27 | }); |
38 | 28 | }); |
0 commit comments