Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about spy on a function #262

Closed
fool2fish opened this issue Mar 28, 2013 · 3 comments
Closed

question about spy on a function #262

fool2fish opened this issue Mar 28, 2013 · 3 comments

Comments

@fool2fish
Copy link

in api doc, it is said a spy could be created by this way:

var spy = sinon.spy(myFunc);
Spies on the provided function

my code:

function a(){}
function b(){}
function fn(args){
    args ? a(args) : b(args)
}
var spy = sinon.spy(a)
it('excute function a if args is true', function(){
    fn(1)
    expect(spy.calledOnce).to.be.ok() // failed
    fn(true)
    expect(spy.calledTwice).to.be.ok() // failed too
})

why?

@mantoni
Copy link
Member

mantoni commented Mar 28, 2013

sinon.spy returns a new function which wraps the given function. You would have to call the returned function so that Sinon can cound calls for you.

@fool2fish
Copy link
Author

3ku

but can some examples could be given to show that sinon.spy() and sinon.spy(fn) are useful in practice?

@cjohansen
Copy link
Contributor

Please use the mailing list when you need help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants