diff --git a/render/tests/test-updateElement.js b/render/tests/test-updateElement.js index 0e0332b7..8a190a4c 100644 --- a/render/tests/test-updateElement.js +++ b/render/tests/test-updateElement.js @@ -205,6 +205,72 @@ o.spec("updateElement", function() { o(updated.dom.style.color).equals("red") }) + o("setting style to `null` removes all styles", function() { + var vnode = {"tag": "p", attrs: {style: "background-color: red"}} + var updated = {"tag": "p", attrs: {style: null}} + + render(root, [vnode]) + + o("style" in vnode.dom.attributes).equals(true) + o(vnode.dom.attributes.style.value).equals("background-color: red;") + + render(root, [updated]) + + //browsers disagree here + try { + + o(updated.dom.attributes.style.value).equals("") + + } catch (e) { + + o("style" in updated.dom.attributes).equals(false) + + } + }) + o("setting style to `undefined` removes all styles", function() { + var vnode = {"tag": "p", attrs: {style: "background-color: red"}} + var updated = {"tag": "p", attrs: {style: undefined}} + + render(root, [vnode]) + + o("style" in vnode.dom.attributes).equals(true) + o(vnode.dom.attributes.style.value).equals("background-color: red;") + + render(root, [updated]) + + //browsers disagree here + try { + + o(updated.dom.attributes.style.value).equals("") + + } catch (e) { + + o("style" in updated.dom.attributes).equals(false) + + } + }) + o("not setting style removes all styles", function() { + var vnode = {"tag": "p", attrs: {style: "background-color: red"}} + var updated = {"tag": "p", attrs: {}} + + render(root, [vnode]) + + o("style" in vnode.dom.attributes).equals(true) + o(vnode.dom.attributes.style.value).equals("background-color: red;") + + render(root, [updated]) + + //browsers disagree here + try { + + o(updated.dom.attributes.style.value).equals("") + + } catch (e) { + + o("style" in updated.dom.attributes).equals(false) + + } + }) o("replaces el", function() { var vnode = {tag: "a"} var updated = {tag: "b"} diff --git a/test-utils/domMock.js b/test-utils/domMock.js index 148b840d..7a5c5b74 100644 --- a/test-utils/domMock.js +++ b/test-utils/domMock.js @@ -247,7 +247,7 @@ module.exports = function(options) { } } } - cssText = buf.join(" ") + element.setAttribute("style", cssText = buf.join(" ")) } } }) diff --git a/test-utils/tests/test-domMock.js b/test-utils/tests/test-domMock.js index 4662ef52..805f7b92 100644 --- a/test-utils/tests/test-domMock.js +++ b/test-utils/tests/test-domMock.js @@ -618,6 +618,7 @@ o.spec("domMock", function() { o(div.style.backgroundColor).equals("red") o(div.style.borderBottom).equals("1px solid red") + o(div.attributes.style.value).equals("background-color: red; border-bottom: 1px solid red;") }) o("removing via setting style.cssText string works", function() { var div = $document.createElement("div") @@ -625,6 +626,7 @@ o.spec("domMock", function() { div.style.cssText = "" o(div.style.background).equals("") + o(div.attributes.style.value).equals("") }) o("the final semicolon is optional when setting style.cssText", function() { var div = $document.createElement("div") @@ -632,6 +634,7 @@ o.spec("domMock", function() { o(div.style.background).equals("red") o(div.style.cssText).equals("background: red;") + o(div.attributes.style.value).equals("background: red;") }) o("'cssText' as a property name is ignored when setting style.cssText", function(){ var div = $document.createElement("div")