chaijs / sinon-chai

Extends Chai with assertions for the Sinon.JS mocking framework.
Other
1.09k stars 107 forks source link

alwaysCalledWithExactly failing #27

Closed jednano closed 11 years ago

jednano commented 11 years ago

Example code:

var chai = require('chai');
var sinon = require('sinon');

chai.use(require('sinon-chai'));

var context = {
    report: function() {
    }
};

global.expect = chai.expect;
global.context = context;
global.reporter = sinon.spy(context, 'report');

it('should report foo', function() {
    context.report('foo');
    expect(reporter).to.have.been.calledOnce;
    expect(reporter).to.have.been.calledWithExactly('foo');
    context.report('foo');
    expect(reporter).to.have.been.calledTwice;
    expect(reporter).to.have.been.alwaysCalledWithExactly('foo');
});

Running the above test gives me the error:

  1)  should report foo:
     TypeError: Object #<Assertion> has no method 'alwaysCalledWithExactly'
      at Context.<anonymous> (Z:\Documents\GitHub\eclint\test\lib\rules\common.js:22:35)
      at Test.Runnable.run (Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runnable.js:211:32)
      at Runner.runTest (Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runner.js:355:10)
      at Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runner.js:401:12
      at next (Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runner.js:281:14)
      at Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runner.js:290:7
      at next (Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runner.js:234:23)
      at Object._onImmediate (Z:\Documents\GitHub\eclint\node_modules\mocha\lib\runner.js:258:5)
      at processImmediate [as _immediateCallback] (timers.js:330:15)
jednano commented 11 years ago
expect(reporter.alwaysCalledWithExactly('foo')).to.be.ok;

fixes the issue, so it must be this library, right?

domenic commented 11 years ago

From the readme:

Sinon.JS property/method Sinon–Chai assertion
alwaysCalledWithExactly spy.should.always.have.been.calledWithExactly(...args)
jednano commented 11 years ago

Oh! OK – so I had to use the word always in the chain. I fixed it with...

expect(reporter).to.always.have.been.calledWithExactly('foo');

Thanks.