Skip to content

Commit e31f4b6

Browse files
committed
test fixes
1 parent 6e58b34 commit e31f4b6

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
},
2525
"scripts": {
2626
"test": "jest --coverage && lerna run test",
27+
"test:watch": "jest --watch",
2728
"coveralls": "cat ./coverage/lcov.info | coveralls",
28-
"watch:test": "jest --watch",
2929
"pretest": "lerna run flow",
3030
"prettify": "prettier --write 'packages/**/*.js'",
3131
"bootstrap": "lerna bootstrap"

packages/container-query/src/adjustContainer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function adjustContainer(
7272

7373
// Normalise to a single changeSet that can be applied by applyStylesToElements
7474
const changeSet = changedStyles[selector].addStyle || {};
75+
7576
if (Array.isArray(changedStyles[selector].removeProps)) {
7677
changedStyles[selector].removeProps.forEach(prop => {
7778
changeSet[prop] = "";

packages/container-query/src/adjustContainer.spec.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import adjustContainer from "./adjustContainer";
22
import containerRegistry from "./containerRegistry";
33
import { SELECTOR, QUERIES } from "@zeecoder/container-query-meta-builder";
4+
import getContainerSize from "./getContainerSize";
5+
import getChangedStyles from "./getChangedStyles";
46

57
jest.mock("./getChangedStyles");
68
jest.mock("./getContainerSize");
79

810
beforeEach(() => {
9-
require("./getChangedStyles").default.mockClear();
10-
require("./getContainerSize").default.mockClear();
11+
getChangedStyles.mockClear();
12+
getContainerSize.mockClear();
1113
});
1214

1315
test("should ignore call if the element is not registered", () => {
14-
const getContainerSize = require("./getContainerSize").default;
1516
const containerElement = document.createElement("div");
1617
adjustContainer(containerElement);
1718
expect(getContainerSize).toHaveBeenCalledTimes(0);
1819
});
1920

2021
test("should be able to get the container size itself, and ignore empty change sets", () => {
21-
const getChangedStyles = require("./getChangedStyles").default;
22-
const getContainerSize = require("./getContainerSize").default;
2322
const containerElement = document.createElement("div");
2423
const containerSize = { width: 1, height: 2 };
2524
getContainerSize.mockImplementationOnce(() => containerSize);
@@ -46,8 +45,6 @@ test("should be able to get the container size itself, and ignore empty change s
4645
});
4746

4847
test("should apply changed styles", () => {
49-
const getChangedStyles = require("./getChangedStyles").default;
50-
const getContainerSize = require("./getContainerSize").default;
5148
const containerElement = document.createElement("div");
5249
const containerChildElement1 = document.createElement("div");
5350
const containerChildElement2 = document.createElement("div");
@@ -101,8 +98,6 @@ test("should apply changed styles", () => {
10198
});
10299

103100
test("should respect container boundaries while applying styles", () => {
104-
const getChangedStyles = require("./getChangedStyles").default;
105-
const getContainerSize = require("./getContainerSize").default;
106101
const container1 = document.createElement("div");
107102
const container2 = document.createElement("div");
108103
const container1Descendant1 = document.createElement("div");

packages/container-query/src/applyStylesToElements.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export default function applyStylesToElements(styles, elements) {
77

88
for (let i = 0; i < elementsLength; i++) {
99
for (let prop in styles) {
10-
elements[i].style.setProperty(prop, styles[prop]);
10+
elements[i].style[prop] = styles[prop];
11+
// Equivalent to setProperty, see: https://devdocs.io/dom/cssstyledeclaration/setproperty
1112
}
1213
}
1314
}

packages/container-query/src/applyStylesToElements.spec.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ import applyStylesToElements from "./applyStylesToElements";
22

33
test("should apply all declarations to all the elements", () => {
44
const element1 = {
5-
style: {
6-
setProperty: jest.fn()
7-
}
5+
style: {}
86
};
97
const element2 = {
10-
style: {
11-
setProperty: jest.fn()
12-
}
8+
style: {}
139
};
1410

1511
const elements = [element1, element2];
@@ -21,17 +17,6 @@ test("should apply all declarations to all the elements", () => {
2117

2218
applyStylesToElements(style, elements);
2319

24-
expect(element1.style.setProperty).toHaveBeenCalledTimes(2);
25-
expect(element1.style.setProperty).toHaveBeenCalledWith("font-size", "42px");
26-
expect(element1.style.setProperty).toHaveBeenCalledWith(
27-
"line-height",
28-
"50px"
29-
);
30-
31-
expect(element2.style.setProperty).toHaveBeenCalledTimes(2);
32-
expect(element2.style.setProperty).toHaveBeenCalledWith("font-size", "42px");
33-
expect(element2.style.setProperty).toHaveBeenCalledWith(
34-
"line-height",
35-
"50px"
36-
);
20+
expect(element1.style).toEqual(style);
21+
expect(element2.style).toEqual(style);
3722
});

0 commit comments

Comments
 (0)