-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (31 loc) · 944 Bytes
/
test.js
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
const test = require("ava");
const loremPix = require(".");
// https://github.com/image-size/image-size
const measure = (data) => {
const buffer = Buffer.from(data.split(",")[1], "base64");
return {
width: buffer.readUInt32BE(16),
height: buffer.readUInt32BE(20),
};
};
test("With width and height", (t) => {
const data = loremPix(10, 20);
t.true(typeof data === "string");
t.true(data.includes("base64") && data.includes("png"));
const { width, height } = measure(data);
t.is(width, 10);
t.is(height, 20);
});
test("With only width", (t) => {
const data = loremPix(11);
t.true(typeof data === "string");
t.true(data.includes("base64") && data.includes("png"));
const { width, height } = measure(data);
t.is(width, 11);
t.is(height, 11);
});
test("Throw without arguments", (t) => {
t.throws(() => loremPix(), {
instanceOf: RangeError,
});
});