Quantcast
Channel: User user2297996 - Stack Overflow
Viewing all articles
Browse latest Browse all 39

How to put a spy to a single function using SinonJS?

$
0
0

I have this:

import * as sinon from 'sinon';import {someFunc, someOtherFunc} from 'someModule';describe("Something", () => {  let sandbox: sinon.SinonSandbox;  beforeEach('setup sandbox', function() {    sandbox = sinon.createSandbox();  });  afterEach('restore sandbox', function() {    sandbox.restore();  });  it("SomeTest", async () => {    const spy = sanbox.spy(someFunc);    someOtherFunc(1);    console.log(spy.callCount) // prints 0  })

someFunc() is just a simple function, it is exported like:

export function someFunc(...)

It is called by someOtherFunc(). Yet, the spy never gets called. The number of calls is 0.

Is it not possible to use Sinon this way? This works fine with Jest.

I think it's not working because sinon doesn't replace the function with the spy.

I also tried to put a spy to the module itself:

import * as lib from 'someModule'... it("SomeTest", async () => {    const spy = sanbox.spy(lib);    lib.someOtherFunc(1);    console.log(spy.someFunc.callCount) // prints 0  })

But this produces the same results. 0 calls.


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>