Skip to content

Commit 0a8ea69

Browse files
committed
Rename method
1 parent b78c3d4 commit 0a8ea69

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

lib/CSSStyleDeclaration.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,11 @@ class CSSStyleDeclaration {
291291

292292
/**
293293
* Non-standard.
294-
* Use this method to set the computed and read-only flags after the value of getComputedStyle()
295-
* has been resolved.
296-
* @param {object} opt - Options
294+
* Use this method to set the read-only flag after getComputedStyle() has been resolved.
297295
* @returns {void}
298296
*/
299-
setOptions(opt = {}) {
300-
for (const [key, value] of Object.entries(opt)) {
301-
if (key === "computed") {
302-
opt[key] = value;
303-
this._computed = value;
304-
} else if (key === "readOnly") {
305-
opt[key] = value;
306-
this._readonly = value;
307-
}
308-
}
297+
setReadOnlyFlag() {
298+
this._readonly = true;
309299
}
310300

311301
// Internal methods

test/CSSStyleDeclaration.test.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe("CSSStyleDeclaration", () => {
8585
});
8686
});
8787

88-
it("getting cssText returns empty string if computedflag is set", () => {
88+
it("getting cssText returns empty string if computed flag is set", () => {
8989
const window = {
9090
getComputedStyle: () => {},
9191
DOMException: globalThis.DOMException
@@ -166,7 +166,28 @@ describe("CSSStyleDeclaration", () => {
166166
assert.strictEqual(style.getPropertyPriority("--foo"), "important");
167167
});
168168

169-
it("removeProperty throws if readonly flag is set", () => {
169+
it("setProperty throws if read-only flag is set", () => {
170+
const window = {
171+
getComputedStyle: () => {},
172+
DOMException: globalThis.DOMException
173+
};
174+
const style = new CSSStyleDeclaration(window);
175+
style.setProperty("color", "green");
176+
style.setReadOnlyFlag();
177+
assert.throws(
178+
() => {
179+
style.setProperty("color", "red");
180+
},
181+
(e) => {
182+
assert.strictEqual(e instanceof window.DOMException, true);
183+
assert.strictEqual(e.name, "NoModificationAllowedError");
184+
assert.strictEqual(e.message, "Property color can not be modified.");
185+
return true;
186+
}
187+
);
188+
});
189+
190+
it("removeProperty throws if read-only flag is set", () => {
170191
const window = {
171192
getComputedStyle: () => {},
172193
DOMException: globalThis.DOMException
@@ -175,9 +196,7 @@ describe("CSSStyleDeclaration", () => {
175196
style.setProperty("--foo", "green");
176197
style.setProperty("--bar", "red");
177198
assert.strictEqual(style.removeProperty("--foo"), "green");
178-
style.setOptions({
179-
readOnly: true
180-
});
199+
style.setReadOnlyFlag();
181200
assert.throws(
182201
() => {
183202
style.removeProperty("--bar");

0 commit comments

Comments
 (0)