【问题标题】:Sinon spy on entire moduleSinon 监视整个模块
【发布时间】:2018-03-08 21:03:53
【问题描述】:

有没有办法监视整个模块并分别检查每个功能?这就是我的意思:

普通间谍:

let spy1 = sinon.spy(_, 'isString');
let spy2 = sinon.spy(_, 'isArray');

expect(spy1)...
expect(spy2)...

我正在寻找类似的东西:

let spy = sinon.spy(_);

expect(spy.isString)...
expect(spy.isArray)...

但不知道怎么做。

谢谢,

【问题讨论】:

标签: javascript unit-testing mocha.js sinon chai


【解决方案1】:

sinon 对此没有一流的支持,我们也不打算为其添加一流的支持。

几行代码不难做到

Object.keys(_).forEach(key => {
  if (typeof _[key] !== 'function') {
    return;
  }
  sinon.spy(_, key)
}

【讨论】:

    猜你喜欢
    • 2018-08-19
    • 2020-05-23
    • 2015-05-13
    • 2018-10-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多