mocks and stubs with oncall

279 views
Skip to first unread message

hale...@gmail.com

unread,
Dec 24, 2017, 1:00:00 PM12/24/17
to Sinon.JS

Hi there!

This is I guess (very) related to https://github.com/sinonjs/sinon/issues/1381. Actually this code:

describe('test onCall', () => {
 class C {
   f() {
     return 1111;
   }
 }

  it('test', () => {
   let c = new C();
   
   let stub = sinon.stub(c, 'f');
   stub.onCall(0).returns(0);
   stub.onCall(1).returns(1);
   expect(c.f()).to.be.equal(0);
   expect(c.f()).to.be.equal(1);
 });

});

is working as expected and the test pass (using chai expect assertions).

However, using mocks, as recommended in the github issue above, just like:
Enter code here...
describe('test onCall', () => {
  class C {
    f() {
      return 1111;
    }
  }

  it('test', () => {
    let c = new C();
let mock = sinon.mock(c);
    let stub = mock.expects('f')
    
stub.onCall(0).returns(0);
stub.onCall(1).returns(1);
expect(c.f()).to.be.equal(0);
expect(c.f()).to.be.equal(1);
  });

});

is not working and I'm getting expectations errors:
1) test onCall
       test:
     ExpectationError: Unexpected call: f()
    Expectation met: f([...]) once

I'd like to use mocks on calls for a more serious tests.
So, am I doing anything wrong or is this an issue on sinon library?

Thanks!!



Reply all
Reply to author
Forward
0 new messages