-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathimageUtils.test.mjs
More file actions
56 lines (53 loc) · 1.5 KB
/
imageUtils.test.mjs
File metadata and controls
56 lines (53 loc) · 1.5 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
45
46
47
48
49
50
51
52
53
54
55
56
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { isSvgImage } from '#site/util/imageUtils';
describe('isSvgImage', () => {
const testCases = [
{
description: 'should return true for a valid .svg URL',
input: 'https://nodejs.org/image.svg',
expected: true,
},
{
description: 'should return true for a URL with query params',
input: 'https://nodejs.org/image.svg?query=param',
expected: true,
},
{
description: 'should return false for a URL without a .svg extension',
input: 'https://nodejs.org/image',
expected: false,
},
{
description:
'should return false for a URL containing ".svg" but not ending with it',
input: 'https://nodejs.org/image.svg.png',
expected: false,
},
{
description: 'should return false for an empty string',
input: '',
expected: false,
},
{
description: 'should return false for a non-URL string',
input: 'not-a-url',
expected: false,
},
];
testCases.forEach(({ description, input, expected }) => {
it(description, () => {
assert.equal(isSvgImage(input), expected);
});
});
});
describe('imageUtils', () => {
describe('isSvgImage', () => {
it('should detect .svg extension properly', () => {
assert.equal(isSvgImage('icon.svg'), true);
});
it('should return false for non-svg source', () => {
assert.equal(isSvgImage('logo.png'), false);
});
});
});