Bypass css text (#2811)

* [DOM mocks] enable setting element.style

* Use the style setter directly
This commit is contained in:
Pierre-Yves Gérardy 2023-01-17 15:04:19 +01:00 committed by GitHub
parent 645cf663b2
commit c1fc1de772
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 13 deletions

View file

@ -346,9 +346,8 @@ module.exports = function(options) {
get style() {
return style
},
set style(_){
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Setting_style
throw new Error("setting element.style is not portable")
set style(value){
this.style.cssText = value
},
get className() {
return this.attributes["class"] ? this.attributes["class"].value : ""

View file

@ -665,16 +665,13 @@ o.spec("domMock", function() {
o(div.style.background).equals("url('/*foo*/')")
})
o("setting style throws", function () {
o("setting style updates style.cssText", function () {
var div = $document.createElement("div")
var err = false
try {
div.style = ""
} catch (e) {
err = e
}
div.style = "background: red;"
o(div.style.background).equals("red")
o(div.style.cssText).equals("background: red;")
o(err instanceof Error).equals(true)
})
})
o.spec("events", function() {