-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
61 lines (49 loc) · 1.43 KB
/
index.test.ts
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
57
58
59
60
61
import parse from "./index";
import { test } from "uvu";
import * as assert from "uvu/assert";
test("parses srcset strings", () => {
const srcset = "[email protected] 2x, dog.jpeg 100w";
assert.equal(parse(srcset), [
{ url: "[email protected]", density: 2 },
{ url: "dog.jpeg", width: 100 },
]);
});
test("ingores extra whitespaces", () => {
const srcset = `
foo-bar.png 2x ,
bar-baz.png 100w`;
assert.equal(parse(srcset), [
{ url: "foo-bar.png", density: 2 },
{ url: "bar-baz.png", width: 100 },
]);
});
test("properly parses float descriptors", () => {
const srcset = "cat.jpeg 2.4x, dog.jpeg 1.5x";
assert.equal(parse(srcset), [
{ url: "cat.jpeg", density: 2.4 },
{ url: "dog.jpeg", density: 1.5 },
]);
});
test("supports URLs that contain comma", () => {
const srcset = `
https://foo.bar/w=100,h=200/dog.png 100w,
https://baz.bar/cat.png?meow=yes 1024w
`;
assert.equal(parse(srcset), [
{ url: "https://foo.bar/w=100,h=200/dog.png", width: 100 },
{ url: "https://baz.bar/cat.png?meow=yes", width: 1024 },
]);
});
test("supports single URLs", () => {
const srcset = "/cat.jpg";
assert.equal(parse(srcset), [{ url: "/cat.jpg" }]);
});
test("supports optional descriptors", () => {
const srcset = "/cat.jpg, /dog.png 3x , /lol ";
assert.equal(parse(srcset), [
{ url: "/cat.jpg" },
{ url: "/dog.png", density: 3 },
{ url: "/lol" },
]);
});
test.run();