How to test the expectation on the eventSpy
Posted
by
Lorraine Bernard
on Stack Overflow
See other posts from Stack Overflow
or by Lorraine Bernard
Published on 2012-06-01T15:07:48Z
Indexed on
2012/06/01
16:40 UTC
Read the original article
Hit count: 334
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));
© Stack Overflow or respective owner