Tests: wrap the rest of the components definitions

This commit is contained in:
Pierre-Yves Gerardy 2017-02-19 02:07:48 +01:00
parent ac38335453
commit 24243dba94
3 changed files with 104 additions and 104 deletions

View file

@ -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}])