这是我第一次使用 Mocha/Sinon/Chai 对 Javacript 进行测试,我不知道是否可以这样做:
var obj = {
    first : function () {
        console.log('make job 1');
    }
};
var objManager = function() {
    $(document).on('event1', obj.first);
};
new objManager();
var spy = sinon.spy(obj, 'first');
describe('Test', function () {
    it('My first test', function () {
        $(document).trigger('event1');
        spy.should.not.have.been.called;
    });
});
我的间谍没有被调用,也不明白为什么......我的函数“obj.first”打印了“make job 1”。
如果我修改我的测试:
it('My first test', function () {
    obj.first();
    spy.should.not.have.been.called;
});
我的间谍被召唤了。所以我的问题是:如何让 sinon spy 与事件一起工作?