Verifying function call and inspecting arguments using sinon spies

前端 未结 3 2147
[愿得一人]
[愿得一人] 2020-12-16 11:08

I would like to verify that bar() is called inside foo() from my unit test.

I figured that Sinon spies might be suitable, but I don\'t know

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 11:38

    Shouldn't you be spying on bar, rather than foo?

    var spy = sinon.spy(bar)
    

    Call foo:

    foo()
    

    Check bar was called:

    console.log(spy.calledOnce)
    

提交回复
热议问题