Tests use hyperscript instead of manually constructing nodes
This commit is contained in:
parent
5502570b16
commit
31d2ed4be8
27 changed files with 1515 additions and 1841 deletions
|
|
@ -3,6 +3,8 @@
|
|||
var o = require("ospec")
|
||||
var domMock = require("../../test-utils/domMock")
|
||||
var vdom = require("../../render/render")
|
||||
var m = require("../../render/hyperscript")
|
||||
m.fragment = require("../../render/fragment")
|
||||
|
||||
o.spec("onupdate", function() {
|
||||
var $window, root, render
|
||||
|
|
@ -15,11 +17,11 @@ o.spec("onupdate", function() {
|
|||
o("does not call onupdate when creating element", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||
var vnode = m("div", {onupdate: create})
|
||||
var updated = m("div", {onupdate: update})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
|
|
@ -28,9 +30,9 @@ o.spec("onupdate", function() {
|
|||
})
|
||||
o("does not call onupdate when removing element", function() {
|
||||
var create = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}}
|
||||
var vnode = m("div", {onupdate: create})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, vnode)
|
||||
render(root, [])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
|
|
@ -38,43 +40,43 @@ o.spec("onupdate", function() {
|
|||
o("does not call onupdate when replacing keyed element", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {onupdate: create}}
|
||||
var updated = {tag: "a", key: 1, attrs: {onupdate: update}}
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
var vnode = m("div", {key: 1, onupdate: create})
|
||||
var updated = m("a", {key: 1, onupdate: update})
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(0)
|
||||
})
|
||||
o("does not recycle when there's an onupdate", function() {
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||
var updated = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||
var vnode = m("div", {key: 1, onupdate: update})
|
||||
var updated = m("div", {key: 1, onupdate: update})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, vnode)
|
||||
render(root, [])
|
||||
render(root, [updated])
|
||||
render(root, updated)
|
||||
|
||||
o(vnode.dom).notEquals(updated.dom)
|
||||
})
|
||||
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
||||
var create = o.spy()
|
||||
var vnode = {tag: "a", attrs: {onupdate: create}}
|
||||
var updated = {tag: "a"}
|
||||
var vnode = m("a", {onupdate: create})
|
||||
var updated = m("a")
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
})
|
||||
o("calls onupdate when noop", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||
var vnode = m("div", {onupdate: create})
|
||||
var updated = m("div", {onupdate: update})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
|
|
@ -84,11 +86,11 @@ o.spec("onupdate", function() {
|
|||
o("calls onupdate when updating attr", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update, id: "a"}, state: {}}
|
||||
var vnode = m("div", {onupdate: create})
|
||||
var updated = m("div", {onupdate: update, id: "a"})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
|
|
@ -98,25 +100,11 @@ o.spec("onupdate", function() {
|
|||
o("calls onupdate when updating children", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [{tag: "a"}], state: {}}
|
||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "b"}], state: {}}
|
||||
var vnode = m("div", {onupdate: create}, m("a"))
|
||||
var updated = m("div", {onupdate: update}, m("b"))
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating text", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "#", attrs: {onupdate: create}, children: "a", state: {}}
|
||||
var updated = {tag: "#", attrs: {onupdate: update}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
|
|
@ -126,25 +114,11 @@ o.spec("onupdate", function() {
|
|||
o("calls onupdate when updating fragment", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "[", attrs: {onupdate: create}, children: [], state: {}}
|
||||
var updated = {tag: "[", attrs: {onupdate: update}, children: [], state: {}}
|
||||
var vnode = m.fragment({onupdate: create})
|
||||
var updated = m.fragment({onupdate: update})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
o(update.this).equals(vnode.state)
|
||||
o(update.args[0]).equals(updated)
|
||||
})
|
||||
o("calls onupdate when updating html", function() {
|
||||
var create = o.spy()
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "<", attrs: {onupdate: create}, children: "a", state: {}}
|
||||
var updated = {tag: "<", attrs: {onupdate: update}, children: "a", state: {}}
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
o(create.callCount).equals(0)
|
||||
o(update.callCount).equals(1)
|
||||
|
|
@ -153,19 +127,19 @@ o.spec("onupdate", function() {
|
|||
})
|
||||
o("calls onupdate after full DOM update", function() {
|
||||
var called = false
|
||||
var vnode = {tag: "div", attrs: {id: "1"}, children: [
|
||||
{tag: "a", attrs: {id: "2"}, children: [
|
||||
{tag: "b", attrs: {id: "3"}}
|
||||
]}
|
||||
]}
|
||||
var updated = {tag: "div", attrs: {id: "11"}, children: [
|
||||
{tag: "a", attrs: {onupdate: update, id: "22"}, children: [
|
||||
{tag: "b", attrs: {id: "33"}}
|
||||
]}
|
||||
]}
|
||||
var vnode = m("div", {id: "1"},
|
||||
m("a", {id: "2"},
|
||||
m("b", {id: "3"})
|
||||
)
|
||||
)
|
||||
var updated = m("div", {id: "11"},
|
||||
m("a", {id: "22", onupdate: update},
|
||||
m("b", {id: "33"})
|
||||
)
|
||||
)
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, [updated])
|
||||
render(root, vnode)
|
||||
render(root, updated)
|
||||
|
||||
function update(vnode) {
|
||||
called = true
|
||||
|
|
@ -178,9 +152,9 @@ o.spec("onupdate", function() {
|
|||
})
|
||||
o("does not set onupdate as an event handler", function() {
|
||||
var update = o.spy()
|
||||
var vnode = {tag: "div", attrs: {onupdate: update}, children: []}
|
||||
var vnode = m("div", {onupdate: update})
|
||||
|
||||
render(root, [vnode])
|
||||
render(root, vnode)
|
||||
|
||||
o(vnode.dom.onupdate).equals(undefined)
|
||||
o(vnode.dom.attributes["onupdate"]).equals(undefined)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue