Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit fe0718d

Browse files
committed
test: add testing cases
1 parent 7ab98de commit fe0718d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/load/__tests__/fetchURL.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { encodeDataURL } from '../../save/encodeDataURL.js';
2+
import { fetchURL } from '../fetchURL.js';
3+
4+
describe('testing fetchURL', () => {
5+
test('basic test 1', async () => {
6+
const image = await fetchURL(
7+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAAAAACoBHk5AAAAFklEQVR4XmNggID///+DSCCEskHM/wCAnQr2TY5mOAAAAABJRU5ErkJggg==',
8+
);
9+
expect(image.bitDepth).toBe(8);
10+
expect(image.getRawImage().data).toEqual(
11+
new Uint8Array([
12+
0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 255, 0, 255, 0, 0, 255, 255, 255,
13+
0, 255, 0, 255, 0, 255,
14+
]),
15+
);
16+
});
17+
test('encoded URL must be equal to decoded one', async () => {
18+
const dataURL =
19+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAAAAACoBHk5AAAAFklEQVR4XmNggID///+DSCCEskHM/wCAnQr2TY5mOAAAAABJRU5ErkJggg==';
20+
const image = await fetchURL(dataURL);
21+
const result = encodeDataURL(image);
22+
expect(result).toEqual(dataURL);
23+
});
24+
test('decode from an image url', async () => {
25+
const image = await fetchURL('https://picsum.photos/id/237/150/200');
26+
expect(image.width).toEqual(150);
27+
expect(image.height).toEqual(200);
28+
expect(image.bitDepth).toEqual(8);
29+
});
30+
});

0 commit comments

Comments
 (0)