У меня есть довольно простой набор спецификаций для представления магистрали:
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)
MatrixView делает так, как ожидает спецификация:
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)
Ожидание, что новая модель Matricesсоздается пропуски.Другие две спецификации терпят неудачу, однако, способами, которые меня смущают:
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.
Любая помощьбудет принята с благодарностью.Я определенно нуждаюсь во второй паре глаз на это, поскольку мои немного утомлены прямо сейчас: - /