0

Sinon 给了我一些有趣的错误:

TypeError: Cannot read property 'quoteStrings' of undefined
    at ascii (http://localhost:3500/assets/sinon.js?body=1:164:36)
    at Function.array (http://localhost:3500/assets/sinon.js?body=1:207:25)
    at Object.ascii (http://localhost:3500/assets/sinon.js?body=1:179:26)
    at Object.format (http://localhost:3500/assets/sinon.js?body=1:594:36)
    at Object.<anonymous> (http://localhost:3500/assets/sinon.js?body=1:1065:43)
    at Function.toString (http://localhost:3500/assets/sinon.js?body=1:1744:54)
    at Function.verify (http://localhost:3500/assets/sinon.js?body=1:1761:49)
    at Context.<anonymous> (http://localhost:3500/assets/views/myview_spec.js?body=1:29:21)
    at Test.run (http://localhost:3500/assets/mocha.js:3322:32)
    at Runner.runTest (http://localhost:3500/assets/mocha.js:3630:10)

这是导致它的测试:

    beforeEach ->
      # make a fake collection object
      collection =
        each: ->


      @subject = new App.Views.TaskList collection: collection
      @sandbox = sinon.sandbox.create()

    it 'renders each task in the collection', ->

      task = ['task model']
      @sandbox.stub(@subject.collection, 'each').yields task

      mock = @sandbox.mock(@subject).expects('renderTask')
                                    .withExactArgs(task, skipLayout: true)
      @subject.render()
      mock.verify()

和被测代码:

 render: =>
    @collection.each (task) =>
      @renderTask task

    this

更新:

事实证明,当我更新代码以通过测试时,我没有收到错误:

 render: =>
    @collection.each (task) =>
      @renderTask task, skipLayout: true

    this

所以这一定和 sinon.js 期望失败有关。可能是一个 sinon.js 错误。

4

1 回答 1

0

我在我的代码中看到了完全相同的错误。无法确定提交上游补丁的确切来源,所以我使用存根解决了问题:

mock = @sandbox.stub collection, 'renderTask'

@subject.render()

mock.callCount.should.equal 1
mock.calledWith.should.equal task, skipLayOut: true

丑陋但有效。断言的确切语法将根据您的框架而有所不同;我在示例中使用 chai。

于 2012-07-17T05:32:08.447 回答