我有一个骨干视图一个相当简单的一套规范的:期待的功能与功能调用作为参数
describe 'Avia.MatricesView', ->
beforeEach ->
@model = {
bind: ->
fetch: ->
}
spyOn(Avia, 'Matrices').andReturn(@model)
@matricesView = new Avia.AviaView(addFixtureDiv('fixture'))
describe 'initialization', ->
beforeEach ->
spyOn(@model, 'bind')
spyOn(@model, 'fetch')
@matricesView.initialize()
it 'creates a new Matrices model', ->
expect(Avia.Matrices).toHaveBeenCalledOnce()
it 'binds the model change event to render', ->
expect(@model.bind).toHaveBeenCalledWith('change', @matricesView.render)
it 'fetches the model data', ->
expect(@model.fetch).toHaveBeenCalledWith(success: @matricesView.render, error: @matricesView.showError)
的MatricesView不一样的规格预计:
initialize: =>
@model = new Avia.Matrices()
@model.bind('change', @render)
@model.fetch(success: @render, error: @showError)
showError: =>
alert('An error occurred while fetching data from the server.')
render: =>
html = JST['views/matrices_view_template']()
@el.html(html)
的期望一个新的矩阵模型正在创建通过。其他两个规格失败,不过,在这让我困惑的方法:
Avia.MatricesView initialization binds the model change event to render. (/home/duncan/avia/spec/javascripts/views/matrices_view_spec.js.coffee:21)
Expected spy bind to have been called with [ 'change', Function ] but was called with [ [ 'change', Function ] ] (line ~22)
expect(this.model.bind).toHaveBeenCalledWith('change', this.matricesView.render);
Avia.MatricesView initialization fetches the model data. (/home/duncan/avia/spec/javascripts/views/matrices_view_spec.js.coffee:24)
Expected spy fetch to have been called with [ { success : Function, error : undefined } ] but was called with [ [ { success : Function, error : Function } ] ] (line ~25)
expect(this.model.fetch).toHaveBeenCalledWith({
据我所知,茉莉花认为,通过@matricesView.render
在规范的范围内返回的功能是由@render
返回的功能不同在MatricesView的实例范围内。
另外,我完全不明白为什么@matricesView.showError
在MatricesView中明确定义时未定义。
任何帮助将不胜感激。我肯定需要第二双眼睛在这个像我有点厌倦现在: -/
哈哈,我一直在为今天的大多数寻找答案,也没有发现它!干得好的队友,感谢您更新问题 – StevenMcD