【发布时间】:2014-01-11 14:03:10
【问题描述】:
我遇到了与here 相同的问题
问题的作者提到他能够通过使用独立版本的茉莉花而不是无头 webkit 来解决这个问题。 在我的测试中,我只使用了独立版本的 jasmine,但仍然遇到同样的问题。 这是我的代码:
describe 'Shared Collections Specs', ->
describe 'Channel Collection', ->
describe 'When fetching channels', ->
responseFixture = null
channelCollection = null
server = null
beforeEach ->
channelCollection = new ChannelCollection()
responseFixture = [{id: 3, name: 'foo'}, {id: 1, name: 'bar'}, {id: 2, name: 'baz'}]
server = sinon.fakeServer.create()
server.respondWith('GET', 'enspoint/channels', [
200, {'Content-Type':'application/json'}, JSON.stringify responseFixture
])
afterEach ->
server.restore()
it 'should populate the collection', ->
channelCollection.fetch()
server.respond()
expect(channelCollection.length).toEqual responseFixture.length
集合总是空的,预期长度为 3 它失败并显示Expected 0 to equal 3.
我尝试使用 jasmine waits 和 runs,因为我认为过程中可能存在异步但我得到了相同的结果。
有什么想法吗?
【问题讨论】:
-
您能否也发布您的 Backbone 模型代码?
标签: backbone.js jasmine sinon