0

我正在梳理教程,我很好奇为什么回调被多次调用——在这种情况下是两次。这是我的代码:

'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?
  });
});

有什么见解吗?

4

1 回答 1

1

custom event custom您正在绑定并触发两个事件event

尝试将其更改为custom_event

于 2014-02-13T09:26:43.393 回答