【问题标题】:Unable to populate Backbone collection with sinon + jasmine无法使用 sinon + jasmine 填充 Backbone 集合
【发布时间】: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 waitsruns,因为我认为过程中可能存在异步但我得到了相同的结果。

有什么想法吗?

【问题讨论】:

  • 您能否也发布您的 Backbone 模型代码?

标签: backbone.js jasmine sinon


【解决方案1】:

只是一个无辜的观察,但您的 XHR 夹具中的 URL“enspoint/channels”中可能存在拼写错误。例如,您的意思是“端点/通道”吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    相关资源
    最近更新 更多