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 错误。