From 9f32267259a51db1f3a0dcc8161cf8f219078eec Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Thu, 5 Jan 2017 23:07:47 -0800 Subject: [PATCH] tests: Update tests for false -> "" behavior --- render/tests/test-component.js | 6 +++--- render/tests/test-hyperscript.js | 12 +++++++++--- render/tests/test-normalize.js | 4 ++-- render/tests/test-normalizeChildren.js | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/render/tests/test-component.js b/render/tests/test-component.js index f4aad629..4bb0a3b6 100644 --- a/render/tests/test-component.js +++ b/render/tests/test-component.js @@ -104,7 +104,7 @@ o.spec("component", function() { visible = false render(root, [{tag: component}]) - o(root.firstChild.nodeValue).equals("false") + o(root.firstChild.nodeValue).equals("") }) o("updates root from null to null", function() { var component = { @@ -232,7 +232,7 @@ o.spec("component", function() { render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) - o(root.firstChild.nodeValue).equals("false") + o(root.firstChild.nodeValue).equals("") }) o("can return null", function() { var component = { @@ -668,7 +668,7 @@ o.spec("component", function() { function init(vnode) { o(vnode.state.data).deepEquals(data) o(vnode.state.data).equals(data) - + //inherits state via prototype component.x = 1 o(vnode.state.x).equals(1) diff --git a/render/tests/test-hyperscript.js b/render/tests/test-hyperscript.js index 8237d0ea..32e767d8 100644 --- a/render/tests/test-hyperscript.js +++ b/render/tests/test-hyperscript.js @@ -229,7 +229,7 @@ o.spec("hyperscript", function() { o("handles falsy boolean single child", function() { var vnode = m("div", {}, [false]) - o(vnode.text).equals(false) + o(vnode.text).equals("") }) o("handles null single child", function() { var vnode = m("div", {}, [null]) @@ -261,7 +261,7 @@ o.spec("hyperscript", function() { var vnode = m("div", {}, [false, true]) o(vnode.children[0].tag).equals("#") - o(vnode.children[0].children).equals(false) + o(vnode.children[0].children).equals("") o(vnode.children[1].tag).equals("#") o(vnode.children[1].children).equals(true) }) @@ -353,10 +353,16 @@ o.spec("hyperscript", function() { o(vnode.text).equals(true) }) o("handles attr and single falsy boolean text child", function() { + var vnode = m("div", {a: "b"}, [0]) + + o(vnode.attrs.a).equals("b") + o(vnode.text).equals(0) + }) + o("handles attr and single false boolean text child", function() { var vnode = m("div", {a: "b"}, [false]) o(vnode.attrs.a).equals("b") - o(vnode.text).equals(false) + o(vnode.text).equals("") }) o("handles attr and single text child unwrapped", function() { var vnode = m("div", {a: "b"}, "c") diff --git a/render/tests/test-normalize.js b/render/tests/test-normalize.js index 7a01af31..237612a4 100644 --- a/render/tests/test-normalize.js +++ b/render/tests/test-normalize.js @@ -48,10 +48,10 @@ o.spec("normalize", function() { o(node.tag).equals("#") o(node.children).equals(true) }) - o("normalizes falsy boolean into text node", function() { + o("normalizes falsy boolean into empty text node", function() { var node = Vnode.normalize(false) o(node.tag).equals("#") - o(node.children).equals(false) + o(node.children).equals("") }) }) diff --git a/render/tests/test-normalizeChildren.js b/render/tests/test-normalizeChildren.js index 9ad2cd89..699f0eab 100644 --- a/render/tests/test-normalizeChildren.js +++ b/render/tests/test-normalizeChildren.js @@ -16,4 +16,10 @@ o.spec("normalizeChildren", function() { o(children[0].tag).equals("#") o(children[0].children).equals("a") }) + o("normalizes `false` values into empty string text nodes", function() { + var children = Vnode.normalizeChildren([false]) + + o(children[0].tag).equals("#") + o(children[0].children).equals("") + }) })