How to test the expectation on the eventSpy
- by Lorraine Bernard
I am trying to test a backbone.model when saving.
Here's my piece of code.
As you can see from the comment there is a problem with toHaveBeenCalledOnce method.
P.S.:
I am using jasmine 1.2.0 and Sinon.JS 1.3.4
describe('when saving', function ()
{
beforeEach(function () {
this.server = sinon.fakeServer.create();
this.responseBody = '{"id":3,"title":"Hello","tags":["garden","weekend"]}';
this.server.respondWith(
'POST',
Routing.generate(this.apiName),
[
200, {'Content-Type': 'application/json'}, this.responseBody
]
);
this.eventSpy = sinon.spy();
});
afterEach(function() {
this.server.restore();
});
it('should not save when title is empty', function() {
this.model.bind('error', this.eventSpy);
this.model.save({'title': ''});
expect(this.eventSpy).toHaveBeenCalledOnce(); // TypeError: Object [object Object] has no method 'toHaveBeenCalledOnce'
expect(this.eventSpy).toHaveBeenCalledWith(this.model, 'cannot have an empty title');
});
});
console.log(expect(this.eventSpy));