coffeescript - How to stub a super() call with Sinon -
i using coffeescript , i'm testing using sinon.js. when testing method invokes method overwrites, how can stub call super()?
e.g., method want test (a backbone.js model):
class whatever extends model validate: (attributes) -> validationerrors = super(attributes) ... validationerrors in example, want make sure super() invoked given attributes , validate returns validation errors super() returns.
like this:
it 'calls super , returns result', -> whatever = new whatever() attributes = sinon.stub() supervalidatestub = sinon.mock(whatever.__super__) supervalidatestub.expects('validate').withexactargs(attributes).returns('validation_result') expect(whatever.validate(attributes)).to.eql('validation_result') supervalidatestub.verify() hope helps anyone.
Comments
Post a Comment