I'm trying to write a simple spec for a Backbone Todos collection which stubs the Backbone Todo model.
Here's my spec:
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 though as todo = new TodoApp.Models.Todo() doens't give an error.
Is it a scoping issue? Could somebody point me in the right direction?
I just ran into that problem too. You should call it like this...
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
The syntax you're using sinon.stub window, 'TodoApp.Models.Todo'
would be for wrapping window['TodoApp.Models.Todo']
as a function. http://sinonjs.org/docs/#stubs
With sinon you're more likely going to be wrapping a particular function on your Todo model with a stub: sinon.stub TodoApp.Models.Todo, 'Foo'
.
Sinon can stub an entire object but I think it's designed to be more granular.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With