我正在梳理本教程,我很好奇为什么回调被多次调用——在这种情况下是两次。这是我的代码:
'use strict';
var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon'),
sinonChai = require('sinon-chai');
var Backbone = require('backbone'),
_ = require('lodash/dist/lodash.underscore');
chai.use(sinonChai);
describe('Backbone.Events', function() {
var myObj;
beforeEach(function() {
myObj = {};
_.extend(myObj, Backbone.Events);
});
it('allows us to bind and trigger custom named events on an object', function() {
var callback = sinon.spy();
myObj.bind('custom event', callback);
myObj.trigger('custom event');
expect(callback).to.have.been.called; // => passes
expect(callback).to.have.been.calledOnce; // => fails??
expect(callback).to.have.been.calledTwice; // => passes, why?
});
});
有什么见解吗?