Trunk jasmine sinon.stub typeError

I am trying to write a simple specification for the Backbone Todos collection, which mutes the Backbone Todo model.

Here is my specification:

describe "TodoApp.Collections.Todos", -> beforeEach -> @todoStub = sinon.stub window, 'TodoApp.Models.Todo' afterEach -> @todoStub.restore() 

This gives me the following error:

 TypeError: Attempted to wrap undefined property TodoApp.Models.Todo as function 

The Todo model is defined as todo = new TodoApp.Models.Todo () does not give an error.

Is this a problem? Can someone point me in the right direction?

+7
source share
2 answers

I also ran into this problem. You should call it that ...

  beforeEach -> @todoStub = sinon.stub window.TodoApp.Models, 'Todo' 

instead of this.

  beforeEach -> @todoStub = sinon.stub window, 'TodoApp.Models.Todo' 

this solved the problem for me

@smek: this also solves your problem from http://tinnedfruit.com/2011/03/25/testing-backbone-apps-with-jasmine-sinon-2.html

+8
source

The syntax that you use sinon.stub window, 'TodoApp.Models.Todo' , is for wrapping window['TodoApp.Models.Todo'] as a function. http://sinonjs.org/docs/#stubs

With sinon, you are likely to wrap a specific function on your Todo model using a stub: sinon.stub TodoApp.Models.Todo, 'Foo' .

Sinon can drown out the whole object , but I think it was more granular.

+1
source

All Articles