Tests: Wrap some component definitions in createComponent() calls
These are the ones that would have been tedious to automate. jscodeshift will handle the remaining ones
This commit is contained in:
parent
90b67b42f0
commit
ac38335453
5 changed files with 43 additions and 43 deletions
|
|
@ -40,7 +40,7 @@ o.spec("mount", function() {
|
|||
o("throws on invalid `root` DOM node", function() {
|
||||
var threw = false
|
||||
try {
|
||||
mount(null, {view: function() {}})
|
||||
mount(null, createComponent({view: function() {}}))
|
||||
} catch (e) {
|
||||
threw = true
|
||||
}
|
||||
|
|
@ -48,11 +48,11 @@ o.spec("mount", function() {
|
|||
})
|
||||
|
||||
o("renders into `root` (POJO component)", function() {
|
||||
mount(root, {
|
||||
mount(root, createComponent({
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
})
|
||||
|
|
@ -78,11 +78,11 @@ o.spec("mount", function() {
|
|||
})
|
||||
|
||||
o("mounting null unmounts", function() {
|
||||
mount(root, {
|
||||
mount(root, createComponent({
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
mount(root, null)
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ o.spec("mount", function() {
|
|||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
mount(root, {
|
||||
mount(root, createComponent({
|
||||
view : function() {
|
||||
return m("div", {
|
||||
oninit : oninit,
|
||||
|
|
@ -105,7 +105,7 @@ o.spec("mount", function() {
|
|||
onclick : onclick,
|
||||
})
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ o.spec("mount", function() {
|
|||
m("#child1")
|
||||
])
|
||||
|
||||
mount(root.childNodes[0], {
|
||||
mount(root.childNodes[0], createComponent({
|
||||
view : function() {
|
||||
return m("div", {
|
||||
oninit : oninit0,
|
||||
|
|
@ -152,12 +152,12 @@ o.spec("mount", function() {
|
|||
onclick : onclick0,
|
||||
})
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
o(oninit0.callCount).equals(1)
|
||||
o(onupdate0.callCount).equals(0)
|
||||
|
||||
mount(root.childNodes[1], {
|
||||
mount(root.childNodes[1], createComponent({
|
||||
view : function() {
|
||||
return m("div", {
|
||||
oninit : oninit1,
|
||||
|
|
@ -165,7 +165,7 @@ o.spec("mount", function() {
|
|||
onclick : onclick1,
|
||||
})
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
o(oninit1.callCount).equals(1)
|
||||
o(onupdate1.callCount).equals(0)
|
||||
|
|
@ -199,7 +199,7 @@ o.spec("mount", function() {
|
|||
|
||||
e.initEvent("click", true, true)
|
||||
|
||||
mount(root, {
|
||||
mount(root, createComponent({
|
||||
view: function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
|
|
@ -209,7 +209,7 @@ o.spec("mount", function() {
|
|||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
|
|
@ -227,14 +227,14 @@ o.spec("mount", function() {
|
|||
var onupdate = o.spy()
|
||||
var oninit = o.spy()
|
||||
|
||||
mount(root, {
|
||||
mount(root, createComponent({
|
||||
view : function() {
|
||||
return m("div", {
|
||||
oninit: oninit,
|
||||
onupdate: onupdate
|
||||
})
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
o(oninit.callCount).equals(1)
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
|
@ -253,7 +253,7 @@ o.spec("mount", function() {
|
|||
timeout(200)
|
||||
|
||||
var i = 0
|
||||
mount(root, {view: function() {i++}})
|
||||
mount(root, createComponent({view: function() {i++}}))
|
||||
var before = i
|
||||
|
||||
redrawService.redraw()
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@ o.spec("component", function() {
|
|||
o("calls oninit before view", function() {
|
||||
var viewCalled = false
|
||||
|
||||
render(root, {
|
||||
render(root, createComponent({
|
||||
tag: {
|
||||
view: function() {
|
||||
viewCalled = true
|
||||
|
|
@ -407,7 +407,7 @@ o.spec("component", function() {
|
|||
o(viewCalled).equals(false)
|
||||
},
|
||||
}
|
||||
})
|
||||
}))
|
||||
})
|
||||
o("does not calls oninit on redraw", function() {
|
||||
var init = o.spy()
|
||||
|
|
@ -661,13 +661,13 @@ o.spec("component", function() {
|
|||
o("initializes state", function() {
|
||||
var called = 0
|
||||
var data = {a: 1}
|
||||
var component = {
|
||||
var component = 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 = {
|
||||
var component = createComponent({
|
||||
data: data,
|
||||
oninit: init,
|
||||
view: function() {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
render(root, [{tag: component}])
|
||||
|
||||
|
|
|
|||
|
|
@ -119,16 +119,16 @@ o.spec("onremove", function() {
|
|||
|
||||
o("calls onremove on nested component", function() {
|
||||
var spy = o.spy()
|
||||
var comp = {
|
||||
var comp = createComponent({
|
||||
view: function() {return m(outer)}
|
||||
}
|
||||
var outer = {
|
||||
})
|
||||
var outer = createComponent({
|
||||
view: function() {return m(inner)}
|
||||
}
|
||||
var inner = {
|
||||
})
|
||||
var inner = createComponent({
|
||||
onremove: spy,
|
||||
view: function() {return m("div")}
|
||||
}
|
||||
})
|
||||
render(root, {tag: comp})
|
||||
render(root, null)
|
||||
|
||||
|
|
@ -136,15 +136,15 @@ o.spec("onremove", function() {
|
|||
})
|
||||
o("calls onremove on nested component child", function() {
|
||||
var spy = o.spy()
|
||||
var comp = {
|
||||
var comp = createComponent({
|
||||
view: function() {return m(outer)}
|
||||
}
|
||||
var outer = {
|
||||
})
|
||||
var outer = createComponent({
|
||||
view: function() {return m(inner, m("a", {onremove: spy}))}
|
||||
}
|
||||
var inner = {
|
||||
})
|
||||
var inner = createComponent({
|
||||
view: function(vnode) {return m("div", vnode.children)}
|
||||
}
|
||||
})
|
||||
render(root, {tag: comp})
|
||||
render(root, null)
|
||||
|
||||
|
|
|
|||
|
|
@ -910,7 +910,7 @@ o.spec("updateNodes", function() {
|
|||
var createComponent = cmp.create
|
||||
|
||||
o("fragment child toggles from null when followed by null component then tag", function() {
|
||||
var component = {view: function() {return null}}
|
||||
var component = createComponent({view: function() {return null}})
|
||||
var vnodes = [{tag: "[", children: [{tag: "a"}, {tag: component}, {tag: "b"}]}]
|
||||
var temp = [{tag: "[", children: [null, {tag: component}, {tag: "b"}]}]
|
||||
var updated = [{tag: "[", children: [{tag: "a"}, {tag: component}, {tag: "b"}]}]
|
||||
|
|
@ -925,8 +925,8 @@ o.spec("updateNodes", function() {
|
|||
})
|
||||
o("fragment child toggles from null in component when followed by null component then tag", function() {
|
||||
var flag = true
|
||||
var a = {view: function() {return flag ? {tag: "a"} : null}}
|
||||
var b = {view: function() {return null}}
|
||||
var a = createComponent({view: function() {return flag ? {tag: "a"} : null}})
|
||||
var b = createComponent({view: function() {return null}})
|
||||
var vnodes = [{tag: "[", children: [{tag: a}, {tag: b}, {tag: "s"}]}]
|
||||
var temp = [{tag: "[", children: [{tag: a}, {tag: b}, {tag: "s"}]}]
|
||||
var updated = [{tag: "[", children: [{tag: a}, {tag: b}, {tag: "s"}]}]
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ o.spec("api", function() {
|
|||
o.spec("m.mount", function() {
|
||||
o("works", function() {
|
||||
var root = window.document.createElement("div")
|
||||
m.mount(root, {view: function() {return m("div")}})
|
||||
m.mount(root, createComponent({view: function() {return m("div")}}))
|
||||
|
||||
o(root.childNodes.length).equals(1)
|
||||
o(root.firstChild.nodeName).equals("DIV")
|
||||
|
|
@ -105,7 +105,7 @@ o.spec("api", function() {
|
|||
o("works", function(done) {
|
||||
var root = window.document.createElement("div")
|
||||
m.route(root, "/a", {
|
||||
"/a": {view: function() {return m("div")}}
|
||||
"/a": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
|
|
@ -119,7 +119,7 @@ o.spec("api", function() {
|
|||
var root = window.document.createElement("div")
|
||||
m.route.prefix("#")
|
||||
m.route(root, "/a", {
|
||||
"/a": {view: function() {return m("div")}}
|
||||
"/a": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
|
|
@ -132,7 +132,7 @@ o.spec("api", function() {
|
|||
o("m.route.get", function(done) {
|
||||
var root = window.document.createElement("div")
|
||||
m.route(root, "/a", {
|
||||
"/a": {view: function() {return m("div")}}
|
||||
"/a": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
|
|
@ -145,7 +145,7 @@ o.spec("api", function() {
|
|||
timeout(100)
|
||||
var root = window.document.createElement("div")
|
||||
m.route(root, "/a", {
|
||||
"/:id": {view: function() {return m("div")}}
|
||||
"/:id": createComponent({view: function() {return m("div")}})
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
|
|
@ -162,7 +162,7 @@ o.spec("api", function() {
|
|||
o("works", function(done) {
|
||||
var count = 0
|
||||
var root = window.document.createElement("div")
|
||||
m.mount(root, {view: function() {count++}})
|
||||
m.mount(root, createComponent({view: function() {count++}}))
|
||||
setTimeout(function() {
|
||||
m.redraw()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue