【发布时间】:2019-06-28 07:10:36
【问题描述】:
我有一个类,我想监视它以检查调用该方法的参数。
class Animal {
constructor() {
this.animals = [];
}
add(animal) {
this.animals.push(animal);
}
}
我的测试文件是这样的
const chai = require('chai');
const sinon = require('sinon');
const Lazy = require('../lazy');
it('should be able to add an animal', function () {
const animal = new Animal();
const add = sinon.spy(animal, 'add');
animal.add('cat')
expect(animal).to.have.been.called.with('cat');
});
间谍没有工作。我想知道如何使用 sinon 检查调用的内容。
【问题讨论】:
-
窥探原型?
-
sinon.spy(Animal.prototype, 'add')?
标签: javascript ecmascript-6 tdd sinon chai