Add tests for components that overwrite their state in oninit
This commit is contained in:
parent
e20fd3f876
commit
0a76772283
1 changed files with 91 additions and 0 deletions
|
|
@ -764,6 +764,97 @@ o.spec("component", function() {
|
||||||
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
o("lifecycle timing megatest (for a single component with the state overwritten)", function() {
|
||||||
|
var methods = {
|
||||||
|
view: o.spy(function(vnode) {
|
||||||
|
o(vnode.state).equals(1)
|
||||||
|
return ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
var attrs = {}
|
||||||
|
var hooks = [
|
||||||
|
"oninit", "oncreate", "onbeforeupdate",
|
||||||
|
"onupdate", "onbeforeremove", "onremove"
|
||||||
|
]
|
||||||
|
hooks.forEach(function(hook) {
|
||||||
|
// the `attrs` hooks are called before the component ones
|
||||||
|
attrs[hook] = o.spy(function(vnode) {
|
||||||
|
o(vnode.state).equals(1)
|
||||||
|
o(attrs[hook].callCount).equals(methods[hook].callCount + 1)
|
||||||
|
})
|
||||||
|
methods[hook] = o.spy(function(vnode) {
|
||||||
|
o(vnode.state).equals(1)
|
||||||
|
o(attrs[hook].callCount).equals(methods[hook].callCount)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
var attrsOninit = attrs.oninit
|
||||||
|
var methodsOninit = methods.oninit
|
||||||
|
attrs.oninit = o.spy(function(vnode){
|
||||||
|
vnode.state = 1
|
||||||
|
return attrsOninit.call(this, vnode)
|
||||||
|
})
|
||||||
|
methods.oninit = o.spy(function(vnode){
|
||||||
|
vnode.state = 1
|
||||||
|
return methodsOninit.call(this, vnode)
|
||||||
|
})
|
||||||
|
|
||||||
|
var component = createComponent(methods)
|
||||||
|
|
||||||
|
o(methods.view.callCount).equals(0)
|
||||||
|
o(methods.oninit.callCount).equals(0)
|
||||||
|
o(methods.oncreate.callCount).equals(0)
|
||||||
|
o(methods.onbeforeupdate.callCount).equals(0)
|
||||||
|
o(methods.onupdate.callCount).equals(0)
|
||||||
|
o(methods.onbeforeremove.callCount).equals(0)
|
||||||
|
o(methods.onremove.callCount).equals(0)
|
||||||
|
|
||||||
|
hooks.forEach(function(hook) {
|
||||||
|
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||||
|
})
|
||||||
|
|
||||||
|
render(root, [{tag: component, attrs: attrs}])
|
||||||
|
|
||||||
|
o(methods.view.callCount).equals(1)
|
||||||
|
o(methods.oninit.callCount).equals(1)
|
||||||
|
o(methods.oncreate.callCount).equals(1)
|
||||||
|
o(methods.onbeforeupdate.callCount).equals(0)
|
||||||
|
o(methods.onupdate.callCount).equals(0)
|
||||||
|
o(methods.onbeforeremove.callCount).equals(0)
|
||||||
|
o(methods.onremove.callCount).equals(0)
|
||||||
|
|
||||||
|
hooks.forEach(function(hook) {
|
||||||
|
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||||
|
})
|
||||||
|
|
||||||
|
render(root, [{tag: component, attrs: attrs}])
|
||||||
|
|
||||||
|
o(methods.view.callCount).equals(2)
|
||||||
|
o(methods.oninit.callCount).equals(1)
|
||||||
|
o(methods.oncreate.callCount).equals(1)
|
||||||
|
o(methods.onbeforeupdate.callCount).equals(1)
|
||||||
|
o(methods.onupdate.callCount).equals(1)
|
||||||
|
o(methods.onbeforeremove.callCount).equals(0)
|
||||||
|
o(methods.onremove.callCount).equals(0)
|
||||||
|
|
||||||
|
hooks.forEach(function(hook) {
|
||||||
|
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||||
|
})
|
||||||
|
|
||||||
|
render(root, [])
|
||||||
|
|
||||||
|
o(methods.view.callCount).equals(2)
|
||||||
|
o(methods.oninit.callCount).equals(1)
|
||||||
|
o(methods.oncreate.callCount).equals(1)
|
||||||
|
o(methods.onbeforeupdate.callCount).equals(1)
|
||||||
|
o(methods.onupdate.callCount).equals(1)
|
||||||
|
o(methods.onbeforeremove.callCount).equals(1)
|
||||||
|
o(methods.onremove.callCount).equals(1)
|
||||||
|
|
||||||
|
hooks.forEach(function(hook) {
|
||||||
|
o(attrs[hook].callCount).equals(methods[hook].callCount)(hook)
|
||||||
|
})
|
||||||
|
})
|
||||||
o("hook state and arguments validation", function(){
|
o("hook state and arguments validation", function(){
|
||||||
var methods = {
|
var methods = {
|
||||||
view: o.spy(function(vnode) {
|
view: o.spy(function(vnode) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue