Skip to content

Commit 1e0f71b

Browse files
committed
Add some more unit tests
1 parent edf29f4 commit 1e0f71b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/__tests__/mediaquery.spec.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,44 @@ describe("match", () => {
9797
)
9898
).toBe(false);
9999
});
100+
101+
it("Width: should return true for a correct match with type", function() {
102+
expect(
103+
mediaQuery.match(
104+
[
105+
{
106+
inverse: false,
107+
type: "screen",
108+
expressions: [
109+
{ modifier: "min", feature: "width", value: "48em" }
110+
]
111+
}
112+
],
113+
{ width: "48em", type: "screen" }
114+
)
115+
).toBe(true);
116+
});
100117
});
101118

102119
describe("Length Check", function() {
103120
describe("Width", function() {
121+
it("should return true for a width equal to a min-width", function() {
122+
expect(
123+
mediaQuery.match(
124+
[
125+
{
126+
inverse: false,
127+
type: "all",
128+
expressions: [
129+
{ modifier: "min", feature: "width", value: "48em" }
130+
]
131+
}
132+
],
133+
{ width: "48em" }
134+
)
135+
).toBe(true);
136+
});
137+
104138
it("should return true for a width higher than a min-width", function() {
105139
expect(
106140
mediaQuery.match(
@@ -135,6 +169,40 @@ describe("match", () => {
135169
).toBe(false);
136170
});
137171

172+
it("should return true for a width lower than a max-width", function() {
173+
expect(
174+
mediaQuery.match(
175+
[
176+
{
177+
expressions: [
178+
{ feature: "width", modifier: "max", value: "48em" }
179+
],
180+
inverse: false,
181+
type: "all"
182+
}
183+
],
184+
{ width: "47.5em" }
185+
)
186+
).toBe(true);
187+
});
188+
189+
it("should return false for a width higher than a max-width", function() {
190+
expect(
191+
mediaQuery.match(
192+
[
193+
{
194+
expressions: [
195+
{ feature: "width", modifier: "max", value: "48em" }
196+
],
197+
inverse: false,
198+
type: "all"
199+
}
200+
],
201+
{ width: "48.5em" }
202+
)
203+
).toBe(false);
204+
});
205+
138206
it("should return false when no width value is specified", function() {
139207
expect(
140208
mediaQuery.match(

0 commit comments

Comments
 (0)