0
我正在梳理this教程,我很好奇爲什麼這個回調被多次調用 - 在這種情況下是兩次。這裏是我的代碼:爲什麼回調連接到一個被稱爲兩次的事件?
'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?
});
});
任何見解?
沒錯吧:)謝謝 – gabeno