I am trying to figure out how to test a Backbone.Collection using sample data but every time I call fetch
on the Collection it does not seem to behave the way I expect it to. For example, using jasmine and coffeescript,
describe "task model", ->
testData = [
{ id: 1, type: "personal", complete: false }
{ id: 2, type: "business", complete: true }
]
collection = null
item = null
testTasks = Alloy.createCollection "task"
addTask = (t) ->
#newTask = new model t
Ti.API.info t
testTasks.add new Alloy.createModel "task", t
# testTasks.length is 2 which is correct
Ti.API.info "testTasks.length after add is #{testTasks.length}"
# add test data to a collection to use for tests/dev
addTask t for t in testData
beforeEach ->
collection = Alloy.createCollection "task", testTasks
item = Alloy.createModel "task"
collection.fetch view
# fails: Expected 0 to be 2
it "has sample data for development", ->
collection.fetch view
expect(collection.length).toEqual 2
I am using a framework called Titanium Alloy which is using BackboneJS 0.9.2