Sinonjs 无法读取未定义的属性“quoteStrings”
Sinonjs Cannot read property 'quoteStrings' of undefined
>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
所以它一定与西农.js期望失败有关。可能是一个西农.js错误。
我在代码中看到完全相同的错误。无法找出提交上游补丁的确切来源,所以我使用存根解决了问题:
mock = @sandbox.stub collection, 'renderTask'
@subject.render()
mock.callCount.should.equal 1
mock.calledWith.should.equal task, skipLayOut: true
丑陋,但它有效。断言的确切语法将根据您的框架而有所不同;我在示例中使用 chai。
相关文章:
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 全局变量和全局对象的属性之间有什么区别吗
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 序列化数据属性中对象的最可靠方法
- 分析高度属性时出现意外值{{specs.height}}.index.html
- TypeError:无法读取属性'推'未定义的JavaScript
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- AngularJS-使用'true'属性
- 可以't使用JavaScript获取width属性
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 如何使用javascript获取嵌套对象中所有子对象的单个属性
- JavaScript Pub/Sub属性访问问题
- 从JavaScript访问struts操作中的属性
- 是否可以从父类访问子类的属性
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何在选项卡上定义属性'的主窗口对象
- 锚点元素的href属性自动更改
- jQuery最近父级的数据属性选择器
- Sinonjs 无法读取未定义的属性“quoteStrings”