0

シノンは私にいくつかの楽しいエラーを与えています:

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

醜いが、それは動作します。アサーションの正確な構文は、フレームワークによって異なります。例ではチャイを使用しています。

于 2012-07-17T05:32:08.447 に答える