Skip to content

Commit e3f9ba4

Browse files
greenkeeper[bot]ZeeCoder
authored andcommitted
chore(package): update jest to version 20.0.4
Yarn upgrade Better test coverage
1 parent d529a9b commit e3f9ba4

File tree

6 files changed

+760
-648
lines changed

6 files changed

+760
-648
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"eslint-config-prettier": "^2.1.0",
4949
"eslint-plugin-prettier": "^2.0.1",
5050
"husky": "^0.13.3",
51-
"jest": "^19.0.2",
51+
"jest": "^20.0.4",
5252
"lint-staged": "^3.4.0",
5353
"prettier": "^1.3.1"
5454
},

src/postcss/detectContainerDefinition.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { DEFINE_CONTAINER_NAME } from "../constants";
22

33
/**
44
* @param {Node} ruleNode
5-
* @param {boolean} [removeDefiniton]
5+
* @param {boolean} [removeDefinition]
66
*
77
* @returns {string|null}
88
*/
99
export default function detectContainerDefinition(
1010
ruleNode,
11-
removeDefiniton = true
11+
removeDefinition = true
1212
) {
1313
let container = null;
1414

@@ -24,7 +24,7 @@ export default function detectContainerDefinition(
2424
}
2525
}
2626

27-
if (removeDefiniton) {
27+
if (removeDefinition) {
2828
ruleNode.nodes.splice(i, 1);
2929
}
3030

src/postcss/detectContainerDefinition.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ test("Return null if no container definition was found", () => {
2626

2727
expect(detectContainerDefinition(ruleNode)).toBeNull();
2828
});
29+
30+
test("should be able to keep container-definition when detected", () => {
31+
const ruleNode = new Node({
32+
selector: ".container"
33+
})
34+
.addNode(new Node({ type: "decl" }))
35+
.addNode(new Node({ type: "atrule", name: DEFINE_CONTAINER_NAME }))
36+
.addNode(new Node({ type: "decl" }));
37+
38+
expect(detectContainerDefinition(ruleNode, false)).toBe(".container");
39+
expect(ruleNode.nodes.length).toBe(3);
40+
expect(ruleNode.nodes[0].type).toBe("decl");
41+
expect(ruleNode.nodes[1].type).toBe("atrule");
42+
expect(ruleNode.nodes[1].name).toBe(DEFINE_CONTAINER_NAME);
43+
expect(ruleNode.nodes[2].type).toBe("decl");
44+
});

src/postcss/getStylesObjectFromNode.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ test("should only accept rule nodes", () => {
66
expect(() => {
77
getStylesObjectFromNode({});
88
}).toThrowError(/^`ruleNode` must be of type "rule".$/);
9+
10+
expect(
11+
getStylesObjectFromNode({
12+
type: "rule",
13+
nodes: null
14+
})
15+
).toEqual({});
916
});
1017

1118
test("should extract all styles", () => {

src/runtime/getConditionFunction.spec.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import getConditionFunction from "./getConditionFunction";
22

3-
test('queries separated by a comma should act as an "or"', () => {
3+
test('should treat multiple conditions as an "or"', () => {
44
// When either width or height is greater than 100
55
const condFn = getConditionFunction([
66
[["width", ">=", 100]],
@@ -22,7 +22,7 @@ test('queries separated by a comma should act as an "or"', () => {
2222
expect(condFn2({ width: 100, height: 20 })).toBe(true);
2323
});
2424

25-
test("non array conditions should return function always returning true", () => {
25+
test("should return a function always returning true for non-array conditions", () => {
2626
const condFn = getConditionFunction();
2727
const condFn2 = getConditionFunction([]);
2828

@@ -35,7 +35,7 @@ test("non array conditions should return function always returning true", () =>
3535
expect(condFn2({ width: 99999, height: 99999 })).toBe(true);
3636
});
3737

38-
test("orientation conditions", () => {
38+
test("should work with orientation conditions", () => {
3939
const portraitCondFn = getConditionFunction([
4040
[["orientation", ":", "portrait"]]
4141
]);
@@ -57,7 +57,7 @@ test("orientation conditions", () => {
5757
expect(landscapeCondFn({ width: 10, height: 100 })).toBe(false);
5858
});
5959

60-
test("width conditions", () => {
60+
test("should work with width conditions", () => {
6161
const ltCondFn = getConditionFunction([[["width", "<", 100]]]);
6262
const lteCondFn = getConditionFunction([[["width", "<=", 100]]]);
6363
const gtCondFn = getConditionFunction([[["width", ">", 100]]]);
@@ -92,7 +92,7 @@ test("width conditions", () => {
9292
expect(gteCondFn({ width: 0 })).toBe(false);
9393
});
9494

95-
test("height conditions", () => {
95+
test("should work with height conditions", () => {
9696
const ltCondFn = getConditionFunction([[["height", "<", 100]]]);
9797
const lteCondFn = getConditionFunction([[["height", "<=", 100]]]);
9898
const gtCondFn = getConditionFunction([[["height", ">", 100]]]);
@@ -127,7 +127,7 @@ test("height conditions", () => {
127127
expect(gteCondFn({ height: 0 })).toBe(false);
128128
});
129129

130-
test("aspect-ratio conditions", () => {
130+
test("should work with aspect-ratio conditions", () => {
131131
const ltCondFn = getConditionFunction([[["aspect-ratio", "<", 1]]]);
132132
const lteCondFn = getConditionFunction([[["aspect-ratio", "<=", 1]]]);
133133
const gtCondFn = getConditionFunction([[["aspect-ratio", ">", 1]]]);
@@ -158,7 +158,7 @@ test("aspect-ratio conditions", () => {
158158
expect(gteCondFn({ width: 10, height: 100 })).toBe(false);
159159
});
160160

161-
test("multiple conditions should work", () => {
161+
test("should work for multiple conditions", () => {
162162
const multiCondFn = getConditionFunction([
163163
[
164164
["orientation", ":", "landscape"],
@@ -174,16 +174,25 @@ test("multiple conditions should work", () => {
174174
expect(multiCondFn({ width: 101, height: 20 })).toBe(true);
175175
});
176176

177-
test("unsupported condition always returns true", () => {
178-
const condFn = getConditionFunction([
177+
test("should return a function always returning true for invalid conditions", () => {
178+
const noCondFn1 = getConditionFunction([
179179
[["something", "that's", "unrecognisable"]]
180180
]);
181181

182-
expect(typeof condFn).toBe("function");
183-
expect(condFn()).toBe(true);
184-
expect(condFn({})).toBe(true);
185-
expect(condFn({ width: 100, height: 100 })).toBe(true);
186-
expect(condFn({ width: 200, height: 100 })).toBe(true);
187-
expect(condFn({ width: 100, height: 200 })).toBe(true);
188-
expect(condFn({ width: 0, height: 0 })).toBe(true);
182+
const noCondFn2 = getConditionFunction([[["width", "?", 1]]]);
183+
expect(typeof noCondFn2).toBe("function");
184+
185+
const noCondFn3 = getConditionFunction([[["height", "?", 1]]]);
186+
expect(typeof noCondFn3).toBe("function");
187+
188+
const noCondFn4 = getConditionFunction([[["aspect-ratio", "?", 1]]]);
189+
expect(typeof noCondFn4).toBe("function");
190+
191+
expect(typeof noCondFn1).toBe("function");
192+
expect(noCondFn1()).toBe(true);
193+
expect(noCondFn1({})).toBe(true);
194+
expect(noCondFn1({ width: 100, height: 100 })).toBe(true);
195+
expect(noCondFn1({ width: 200, height: 100 })).toBe(true);
196+
expect(noCondFn1({ width: 100, height: 200 })).toBe(true);
197+
expect(noCondFn1({ width: 0, height: 0 })).toBe(true);
189198
});

0 commit comments

Comments
 (0)