我试图弄清楚如何使用示例数据测试 Backbone.Collection,但每次我调用fetch
Collection 时,它的行为似乎都不像我期望的那样。例如,使用 jasmine 和 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
我正在使用一个名为 Titanium Alloy 的框架,它使用 BackboneJS 0.9.2