-
Notifications
You must be signed in to change notification settings - Fork 6
/
cssinjs-include-media.test.ts
86 lines (75 loc) · 2.39 KB
/
cssinjs-include-media.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import includeMedia, {
setBreakPoints,
getBreakPoints,
} from "./cssinjs-inlclude-media";
describe("if param num is one", () => {
test("check <phone", () => {
expect(includeMedia("<phone")).toBe("@media (max-width: 374px)");
});
test("check >=tablet", () => {
expect(includeMedia(">=tablet")).toBe("@media (min-width: 768px)");
});
});
describe("get Breakpoints", () => {
test("get breakpoints of library", () => {
expect(getBreakPoints()).toEqual({
smallPhone: 320,
phone: 375,
tablet: 768,
desktop: 1024,
largeDesktop: 1440,
});
});
});
describe("if param num is two", () => {
test("check ( >=phone, <tablet ) ", () => {
expect(includeMedia(">=phone", "<tablet")).toBe(
"@media (min-width: 375px) and (max-width: 767px)"
);
});
test("check ( >phone , <=tablet) ", () => {
expect(includeMedia(">=tablet", "<desktop")).toBe(
"@media (min-width: 768px) and (max-width: 1023px)"
);
});
});
describe("if param is invalid", () => {
test("check param is only num ", () => {
expect(() => includeMedia("500")).toThrowError(
new Error("invalid media-query :(")
);
});
test("check one param is valid , but another param is not valid ", () => {
expect(() => includeMedia("<=desktop", "5000")).toThrowError(
new Error("invalid media-query :(")
);
});
test("check two param is not valid ", () => {
expect(() => includeMedia("<=myphone", "5000")).toThrowError(
new Error("invalid media-query :(")
);
});
});
describe("check if breakpoint is changed", () => {
test("test for breakpoint change", () => {
setBreakPoints({ largeDesktop: 1500 });
expect(includeMedia("<=largeDesktop")).toBe("@media (max-width: 1500px)");
});
test("test for invalid breakpoint change", () => {
expect(() => setBreakPoints({ smallDesktop: 1500 })).toThrowError(
new Error("invalid breakpoint :(")
);
});
describe("check if breakpoint's type is string", () => {
test("test for size of string", () => {
setBreakPoints({ largeDesktop: "150rem" });
expect(includeMedia("<=largeDesktop")).toBe("@media (max-width: 150rem)");
});
test("test for size of css function usage", () => {
setBreakPoints({ largeDesktop: "calc(20 * 18px)" });
expect(includeMedia("<=largeDesktop")).toBe(
"@media (max-width: calc(20 * 18px))"
);
});
});
});