我有一個骨幹視圖一個相當簡單的一套規範的:期待的功能與功能調用作爲參數
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