小编Fra*_*son的帖子

Sinon间谍功能被召唤但未被追踪

我正在使用Mocha和sinon监视函数调用.该函数被正确调用,但间谍没有跟踪它.

这是我正在测试的模块

export default (() => {

  function test1(){
      console.log('called second func');
      return 5;
  }

  function callThis(){
      console.log('called first func');
      test1();
  }

  return {
      test1,
      callThis
  };

})();
Run Code Online (Sandbox Code Playgroud)

这是测试

import Common from './common';

describe('spy test', () => {
  var setSpy = sinon.spy(Common, 'test1');

  Common.callThis();

  var result = setSpy.called;

  it(`does the test`, () => {
      expect(result).to.equal(true);
  });

});
Run Code Online (Sandbox Code Playgroud)

我基本上调用第一个函数,但想检查第二个函数被调用作为结果.控制台日志告诉我这种情况正在发生,但间谍返回false并且没有注意到它正在监视的事情.我错过了什么吗?

javascript mocha.js sinon

3
推荐指数
1
解决办法
712
查看次数

标签 统计

javascript ×1

mocha.js ×1

sinon ×1