From c98f663653b95ce800abf29aa6e0ed8f7b0b735b Mon Sep 17 00:00:00 2001 From: Bruce Lewis Date: Fri, 10 Jun 2016 11:00:56 -0400 Subject: [PATCH] Render booleans as empty strings --- mithril.js | 2 +- test/mithril.render.js | 18 ++++++++++++++++++ tests/mithril-tests.js | 20 +++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mithril.js b/mithril.js index e4a8dc67..9595a439 100644 --- a/mithril.js +++ b/mithril.js @@ -188,7 +188,7 @@ // value of Console.log in some versions of Firefox (behavior depends on // version) try { - if (data != null && data.toString() != null) return data + if (typeof data !== "boolean" && data != null && data.toString() != null) return data } catch (e) { // silently ignore errors } diff --git a/test/mithril.render.js b/test/mithril.render.js index ec6ba1ce..9cd0c95c 100644 --- a/test/mithril.render.js +++ b/test/mithril.render.js @@ -57,6 +57,24 @@ describe("m.render()", function () { expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("") }) + it("renders `null` body to empty string", function () { + var root = mock.document.createElement("div") + m.render(root, m("div", [null])) + expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("") + }) + + it("renders `true` body to empty string", function () { + var root = mock.document.createElement("div") + m.render(root, m("div", [true])) + expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("") + }) + + it("renders `false` body to empty string", function () { + var root = mock.document.createElement("div") + m.render(root, m("div", [false])) + expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("") + }) + it("uses the W3C URI as default namespace for SVG children", function () { var root = mock.document.createElement("div") m.render(root, m("svg", [m("g")])) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 172c6e06..dd5a4b98 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -11,7 +11,7 @@ test(function () { return m(".foo").attrs.className === "foo" }) test(function () { return m("[title=bar]").tag === "div" }) test(function () { return m("[title=bar]").attrs.title === "bar" }) - test(function () { return m("[empty]").attrs.empty === "" }) + test(function () { return m("[empty]").attrs.empty === true }) test(function () { return m("[title=\'bar\']").attrs.title === "bar" }) test(function () { return m("[title=\"bar\"]").attrs.title === "bar" }) test(function () { return m("div", "test").children[0] === "test" }) @@ -1750,6 +1750,24 @@ return root.childNodes[0].childNodes[0].nodeValue === "" }) + test(function () { + var root = mock.document.createElement("div") + m.render(root, m("div", [null])) + return root.childNodes[0].childNodes[0].nodeValue === "" + }) + + test(function () { + var root = mock.document.createElement("div") + m.render(root, m("div", [true])) + return root.childNodes[0].childNodes[0].nodeValue === "" + }) + + test(function () { + var root = mock.document.createElement("div") + m.render(root, m("div", [false])) + return root.childNodes[0].childNodes[0].nodeValue === "" + }) + test(function () { var root = mock.document.createElement("div") m.render(root, m("svg", [m("g")]))