Merge pull request #1284 from barneycarroll/ospec-spy-wrapping
[ospec] allow spy to wrap functions
This commit is contained in:
commit
32fed2dd88
2 changed files with 21 additions and 1 deletions
|
|
@ -19,11 +19,14 @@ module.exports = new function init() {
|
||||||
ctx = parent
|
ctx = parent
|
||||||
}
|
}
|
||||||
o.only = function(subject, predicate) {o(subject, only = predicate)}
|
o.only = function(subject, predicate) {o(subject, only = predicate)}
|
||||||
o.spy = function() {
|
o.spy = function(fn) {
|
||||||
var spy = function() {
|
var spy = function() {
|
||||||
spy.this = this
|
spy.this = this
|
||||||
spy.args = [].slice.call(arguments)
|
spy.args = [].slice.call(arguments)
|
||||||
spy.callCount++
|
spy.callCount++
|
||||||
|
|
||||||
|
if(fn)
|
||||||
|
return fn.apply(this, arguments)
|
||||||
}
|
}
|
||||||
spy.args = []
|
spy.args = []
|
||||||
spy.callCount = 0
|
spy.callCount = 0
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,23 @@ o.spec("ospec", function() {
|
||||||
o(spy.args.length).equals(1)
|
o(spy.args.length).equals(1)
|
||||||
o(spy.args[0]).equals(1)
|
o(spy.args[0]).equals(1)
|
||||||
})
|
})
|
||||||
|
o("spy wrapping", function() {
|
||||||
|
var spy = o.spy(function view(vnode){
|
||||||
|
this.drawn = true
|
||||||
|
|
||||||
|
return {tag: "div", children: vnode.children}
|
||||||
|
})
|
||||||
|
var children = [""]
|
||||||
|
var state = {}
|
||||||
|
|
||||||
|
var output = spy.call(state, {children: children})
|
||||||
|
|
||||||
|
o(spy.callCount).equals(1)
|
||||||
|
o(spy.args.length).equals(1)
|
||||||
|
o(spy.args[0]).deepEquals({children: children})
|
||||||
|
o(state).deepEquals({drawn: true})
|
||||||
|
o(output).deepEquals({tag: "div", children: children})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
o.spec("async", function() {
|
o.spec("async", function() {
|
||||||
var a = 0, b = 0
|
var a = 0, b = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue