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 bug。
答案 0 :(得分:0)
我在代码中看到了完全相同的错误。无法确定提交上游补丁的确切来源,因此我使用了存根:
mock = @sandbox.stub collection, 'renderTask'
@subject.render()
mock.callCount.should.equal 1
mock.calledWith.should.equal task, skipLayOut: true
丑陋但它有效。根据您的框架,断言的确切语法会有所不同;我在示例中使用了chai。