diff --git a/render/tests/test-component.js b/render/tests/test-component.js index 516cd2e8..1ae9ea45 100644 --- a/render/tests/test-component.js +++ b/render/tests/test-component.js @@ -20,11 +20,11 @@ o.spec("component", function() { o.spec("basics", function() { o("works", function() { - var component = { + var component = createComponent({ view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} } - } + }) var node = {tag: component} render(root, [node]) @@ -34,11 +34,11 @@ o.spec("component", function() { o(root.firstChild.firstChild.nodeValue).equals("b") }) o("receives arguments", function() { - var component = { + var component = createComponent({ view: function(vnode) { return {tag: "div", attrs: vnode.attrs, text: vnode.text} } - } + }) var node = {tag: component, attrs: {id: "a"}, text: "b"} render(root, [node]) @@ -48,11 +48,11 @@ o.spec("component", function() { o(root.firstChild.firstChild.nodeValue).equals("b") }) o("updates", function() { - var component = { + var component = createComponent({ view: function(vnode) { return {tag: "div", attrs: vnode.attrs, text: vnode.text} } - } + }) render(root, [{tag: component, attrs: {id: "a"}, text: "b"}]) render(root, [{tag: component, attrs: {id: "c"}, text: "d"}]) @@ -62,11 +62,11 @@ o.spec("component", function() { }) o("updates root from null", function() { var visible = false - var component = { + var component = createComponent({ view: function(vnode) { return visible ? {tag: "div"} : null } - } + }) render(root, [{tag: component}]) visible = true render(root, [{tag: component}]) @@ -75,11 +75,11 @@ o.spec("component", function() { }) o("updates root from primitive", function() { var visible = false - var component = { + var component = createComponent({ view: function(vnode) { return visible ? {tag: "div"} : false } - } + }) render(root, [{tag: component}]) visible = true render(root, [{tag: component}]) @@ -88,11 +88,11 @@ o.spec("component", function() { }) o("updates root to null", function() { var visible = true - var component = { + var component = createComponent({ view: function(vnode) { return visible ? {tag: "div"} : null } - } + }) render(root, [{tag: component}]) visible = false render(root, [{tag: component}]) @@ -101,11 +101,11 @@ o.spec("component", function() { }) o("updates root to primitive", function() { var visible = true - var component = { + var component = createComponent({ view: function(vnode) { return visible ? {tag: "div"} : false } - } + }) render(root, [{tag: component}]) visible = false render(root, [{tag: component}]) @@ -113,22 +113,22 @@ o.spec("component", function() { o(root.firstChild.nodeValue).equals("") }) o("updates root from null to null", function() { - var component = { + var component = createComponent({ view: function(vnode) { return null } - } + }) render(root, [{tag: component}]) render(root, [{tag: component}]) o(root.childNodes.length).equals(0) }) o("removes", function() { - var component = { + var component = createComponent({ view: function(vnode) { return {tag: "div"} } - } + }) var div = {tag: "div", key: 2} render(root, [{tag: component, key: 1}, div]) render(root, [{tag: "div", key: 2}]) @@ -137,21 +137,21 @@ o.spec("component", function() { o(root.firstChild).equals(div.dom) }) o("svg works when creating across component boundary", function() { - var component = { + var component = createComponent({ view: function(vnode) { return {tag: "g"} } - } + }) render(root, [{tag: "svg", children: [{tag: component}]}]) o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg") }) o("svg works when updating across component boundary", function() { - var component = { + var component = createComponent({ view: function(vnode) { return {tag: "g"} } - } + }) render(root, [{tag: "svg", children: [{tag: component}]}]) render(root, [{tag: "svg", children: [{tag: component}]}]) @@ -160,14 +160,14 @@ o.spec("component", function() { }) o.spec("return value", function() { o("can return fragments", function() { - var component = { + var component = createComponent({ view: function(vnode) { return [ {tag: "label"}, {tag: "input"}, ] } - } + }) render(root, [{tag: component}]) o(root.childNodes.length).equals(2) @@ -175,98 +175,98 @@ o.spec("component", function() { o(root.childNodes[1].nodeName).equals("INPUT") }) o("can return string", function() { - var component = { + var component = createComponent({ view: function(vnode) { return "a" } - } + }) render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) o(root.firstChild.nodeValue).equals("a") }) o("can return falsy string", function() { - var component = { + var component = createComponent({ view: function(vnode) { return "" } - } + }) render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) o(root.firstChild.nodeValue).equals("") }) o("can return number", function() { - var component = { + var component = createComponent({ view: function(vnode) { return 1 } - } + }) render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) o(root.firstChild.nodeValue).equals("1") }) o("can return falsy number", function() { - var component = { + var component = createComponent({ view: function(vnode) { return 0 } - } + }) render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) o(root.firstChild.nodeValue).equals("0") }) o("can return boolean", function() { - var component = { + var component = createComponent({ view: function(vnode) { return true } - } + }) render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) o(root.firstChild.nodeValue).equals("true") }) o("can return falsy boolean", function() { - var component = { + var component = createComponent({ view: function(vnode) { return false } - } + }) render(root, [{tag: component}]) o(root.firstChild.nodeType).equals(3) o(root.firstChild.nodeValue).equals("") }) o("can return null", function() { - var component = { + var component = createComponent({ view: function(vnode) { return null } - } + }) render(root, [{tag: component}]) o(root.childNodes.length).equals(0) }) o("can return undefined", function() { - var component = { + var component = createComponent({ view: function(vnode) { return undefined } - } + }) render(root, [{tag: component}]) o(root.childNodes.length).equals(0) }) o("throws a custom error if it returns itself", function() { // A view that returns its vnode would otherwise trigger an infinite loop - var component = { + var component = createComponent({ view: function(vnode) { return vnode } - } + }) try { render(root, [{tag: component}]) } @@ -277,14 +277,14 @@ o.spec("component", function() { } }) o("can update when returning fragments", function() { - var component = { + var component = createComponent({ view: function(vnode) { return [ {tag: "label"}, {tag: "input"}, ] } - } + }) render(root, [{tag: component}]) render(root, [{tag: component}]) @@ -293,11 +293,11 @@ o.spec("component", function() { o(root.childNodes[1].nodeName).equals("INPUT") }) o("can update when returning primitive", function() { - var component = { + var component = createComponent({ view: function(vnode) { return "a" } - } + }) render(root, [{tag: component}]) render(root, [{tag: component}]) @@ -305,25 +305,25 @@ o.spec("component", function() { o(root.firstChild.nodeValue).equals("a") }) o("can update when returning null", function() { - var component = { + var component = createComponent({ view: function(vnode) { return null } - } + }) render(root, [{tag: component}]) render(root, [{tag: component}]) o(root.childNodes.length).equals(0) }) o("can remove when returning fragments", function() { - var component = { + var component = createComponent({ view: function(vnode) { return [ {tag: "label"}, {tag: "input"}, ] } - } + }) var div = {tag: "div", key: 2} render(root, [{tag: component, key: 1}, div]) @@ -333,11 +333,11 @@ o.spec("component", function() { o(root.firstChild).equals(div.dom) }) o("can remove when returning primitive", function() { - var component = { + var component = createComponent({ view: function(vnode) { return "a" } - } + }) var div = {tag: "div", key: 2} render(root, [{tag: component, key: 1}, div]) @@ -350,7 +350,7 @@ o.spec("component", function() { o.spec("lifecycle", function() { o("calls oninit", function() { var called = 0 - var component = { + var component = createComponent({ oninit: function(vnode) { called++ @@ -361,7 +361,7 @@ o.spec("component", function() { view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} } - } + }) var node = {tag: component} render(root, [node]) @@ -373,7 +373,7 @@ o.spec("component", function() { }) o("calls oninit when returning fragment", function() { var called = 0 - var component = { + var component = createComponent({ oninit: function(vnode) { called++ @@ -384,7 +384,7 @@ o.spec("component", function() { view: function() { return [{tag: "div", attrs: {id: "a"}, text: "b"}] } - } + }) var node = {tag: component} render(root, [node]) @@ -411,12 +411,12 @@ o.spec("component", function() { }) o("does not calls oninit on redraw", function() { var init = o.spy() - var component = { + var component = createComponent({ view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} }, oninit: init, - } + }) function view() { return {tag: component} @@ -429,7 +429,7 @@ o.spec("component", function() { }) o("calls oncreate", function() { var called = 0 - var component = { + var component = createComponent({ oncreate: function(vnode) { called++ @@ -440,7 +440,7 @@ o.spec("component", function() { view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} } - } + }) var node = {tag: component} render(root, [node]) @@ -452,12 +452,12 @@ o.spec("component", function() { }) o("does not calls oncreate on redraw", function() { var create = o.spy() - var component = { + var component = createComponent({ view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} }, oncreate: create, - } + }) function view() { return {tag: component} @@ -470,7 +470,7 @@ o.spec("component", function() { }) o("calls oncreate when returning fragment", function() { var called = 0 - var component = { + var component = createComponent({ oncreate: function(vnode) { called++ @@ -481,7 +481,7 @@ o.spec("component", function() { view: function() { return [{tag: "div", attrs: {id: "a"}, text: "b"}] } - } + }) var node = {tag: component} render(root, [node]) @@ -493,7 +493,7 @@ o.spec("component", function() { }) o("calls onupdate", function() { var called = 0 - var component = { + var component = createComponent({ onupdate: function(vnode) { called++ @@ -504,7 +504,7 @@ o.spec("component", function() { view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} } - } + }) render(root, [{tag: component}]) @@ -519,7 +519,7 @@ o.spec("component", function() { }) o("calls onupdate when returning fragment", function() { var called = 0 - var component = { + var component = createComponent({ onupdate: function(vnode) { called++ @@ -530,7 +530,7 @@ o.spec("component", function() { view: function() { return [{tag: "div", attrs: {id: "a"}, text: "b"}] } - } + }) render(root, [{tag: component}]) @@ -545,7 +545,7 @@ o.spec("component", function() { }) o("calls onremove", function() { var called = 0 - var component = { + var component = createComponent({ onremove: function(vnode) { called++ @@ -556,7 +556,7 @@ o.spec("component", function() { view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} } - } + }) render(root, [{tag: component}]) @@ -569,7 +569,7 @@ o.spec("component", function() { }) o("calls onremove when returning fragment", function() { var called = 0 - var component = { + var component = createComponent({ onremove: function(vnode) { called++ @@ -580,7 +580,7 @@ o.spec("component", function() { view: function() { return [{tag: "div", attrs: {id: "a"}, text: "b"}] } - } + }) render(root, [{tag: component}]) @@ -593,7 +593,7 @@ o.spec("component", function() { }) o("calls onbeforeremove", function() { var called = 0 - var component = { + var component = createComponent({ onbeforeremove: function(vnode) { called++ @@ -604,7 +604,7 @@ o.spec("component", function() { view: function() { return {tag: "div", attrs: {id: "a"}, text: "b"} } - } + }) render(root, [{tag: component}]) @@ -617,7 +617,7 @@ o.spec("component", function() { }) o("calls onbeforeremove when returning fragment", function() { var called = 0 - var component = { + var component = createComponent({ onbeforeremove: function(vnode) { called++ @@ -628,7 +628,7 @@ o.spec("component", function() { view: function() { return [{tag: "div", attrs: {id: "a"}, text: "b"}] } - } + }) render(root, [{tag: component}]) @@ -640,12 +640,12 @@ o.spec("component", function() { o(root.childNodes.length).equals(0) }) o("does not recycle when there's an onupdate", function() { - var component = { + var component = createComponent({ onupdate: function() {}, view: function() { return {tag: "div"} } - } + }) var update = o.spy() var vnode = {tag: component, key: 1} var updated = {tag: component, key: 1} @@ -661,13 +661,13 @@ o.spec("component", function() { o("initializes state", function() { var called = 0 var data = {a: 1} - var component = createComponent({ + var component = createComponent(createComponent({ data: data, oninit: init, view: function() { return "" } - }) + })) render(root, [{tag: component}]) @@ -679,13 +679,13 @@ o.spec("component", function() { var called = 0 var body = {a: 1} var data = [body] - var component = createComponent({ + var component = createComponent(createComponent({ data: data, oninit: init, view: function() { return "" } - }) + })) render(root, [{tag: component}]) diff --git a/render/tests/test-onbeforeremove.js b/render/tests/test-onbeforeremove.js index 0a3ca8fe..050d1758 100644 --- a/render/tests/test-onbeforeremove.js +++ b/render/tests/test-onbeforeremove.js @@ -176,11 +176,11 @@ o.spec("onbeforeremove", function() { o("finalizes the remove phase asynchronously when promise is returned synchronously from both attrs- and tag.onbeforeremove", function(done) { var onremove = o.spy() var onbeforeremove = function(){return Promise.resolve()} - var component = { + var component = createComponent({ onbeforeremove: onbeforeremove, onremove: onremove, view: function() {}, - } + }) render(root, [{tag: component, attrs: {onbeforeremove: onbeforeremove, onremove: onremove}}]) render(root, []) callAsync(function() { @@ -192,11 +192,11 @@ o.spec("onbeforeremove", function() { var view = o.spy() var onremove = o.spy() var onbeforeremove = function(){return new Promise(function(resolve){callAsync(resolve)})} - var component = { + var component = createComponent({ onbeforeremove: onbeforeremove, onremove: onremove, view: view, - } + }) render(root, [{tag: component}]) render(root, []) diff --git a/render/tests/test-onbeforeupdate.js b/render/tests/test-onbeforeupdate.js index d637ab66..626b9ddc 100644 --- a/render/tests/test-onbeforeupdate.js +++ b/render/tests/test-onbeforeupdate.js @@ -125,12 +125,12 @@ o.spec("onbeforeupdate", function() { var createComponent = cmp.create o("prevents update in component", function() { - var component = { + var component = createComponent({ onbeforeupdate: function() {return false}, view: function(vnode) { return {tag: "div", children: vnode.children} }, - } + }) var vnode = {tag: component, children: [{tag: "#", children: "a"}]} var updated = {tag: component, children: [{tag: "#", children: "b"}]} @@ -141,12 +141,12 @@ o.spec("onbeforeupdate", function() { }) o("prevents update if returning false in component and false in vnode", function() { - var component = { + var component = createComponent({ onbeforeupdate: function() {return false}, view: function(vnode) { return {tag: "div", attrs: {id: vnode.attrs.id}} }, - } + }) var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}} var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}} @@ -157,12 +157,12 @@ o.spec("onbeforeupdate", function() { }) o("does not prevent update if returning true in component and true in vnode", function() { - var component = { + var component = createComponent({ onbeforeupdate: function() {return true}, view: function(vnode) { return {tag: "div", attrs: {id: vnode.attrs.id}} }, - } + }) var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}} var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}} @@ -173,12 +173,12 @@ o.spec("onbeforeupdate", function() { }) o("does not prevent update if returning false in component but true in vnode", function() { - var component = { + var component = createComponent({ onbeforeupdate: function() {return false}, view: function(vnode) { return {tag: "div", attrs: {id: vnode.attrs.id}} }, - } + }) var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}} var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}} @@ -189,12 +189,12 @@ o.spec("onbeforeupdate", function() { }) o("does not prevent update if returning true in component but false in vnode", function() { - var component = { + var component = createComponent({ onbeforeupdate: function() {return true}, view: function(vnode) { return {tag: "div", attrs: {id: vnode.attrs.id}} }, - } + }) var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}} var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}} @@ -205,12 +205,12 @@ o.spec("onbeforeupdate", function() { }) o("does not prevent update if returning true from component", function() { - var component = { + var component = createComponent({ onbeforeupdate: function() {return true}, view: function(vnode) { return {tag: "div", attrs: vnode.attrs} }, - } + }) var vnode = {tag: component, attrs: {id: "a"}} var updated = {tag: component, attrs: {id: "b"}} @@ -221,12 +221,12 @@ o.spec("onbeforeupdate", function() { }) o("accepts arguments for comparison in component", function() { - var component = { + var component = createComponent({ onbeforeupdate: onbeforeupdate, view: function(vnode) { return {tag: "div", attrs: vnode.attrs} }, - } + }) var count = 0 var vnode = {tag: component, attrs: {id: "a"}} var updated = {tag: component, attrs: {id: "b"}} @@ -248,12 +248,12 @@ o.spec("onbeforeupdate", function() { }) o("is not called on component creation", function() { - var component = { + var component = createComponent({ onbeforeupdate: onbeforeupdate, view: function(vnode) { return {tag: "div", attrs: vnode.attrs} }, - } + }) var count = 0 var vnode = {tag: "div", attrs: {id: "a"}} @@ -270,12 +270,12 @@ o.spec("onbeforeupdate", function() { }) o("is called only once on component update", function() { - var component = { + var component = createComponent({ onbeforeupdate: onbeforeupdate, view: function(vnode) { return {tag: "div", attrs: vnode.attrs} }, - } + }) var count = 0 var vnode = {tag: component, attrs: {id: "a"}}