Knockout ViewModel 实例返回空数组 Jasmine Rails Coffeescript



我正在尝试为我的 Knockout ViewModel 编写一个茉莉花规范,但它返回一个空数组,即使当我实际应用数据绑定时它也可以工作。我不确定这是否是因为我如何构建我的 Coffeescript,因为我将所有内容命名为命名空间。

茉莉花规格:

describe 'knockout', ->
  it 'computes available timeslots based on date', ->
    target = new HEALTHFUND.AppointmentViewModel()
    target.date('2014/02/15')
    expect(target.available_timeslots()).toBe([])
    target.date('2014/02/16')
    expect(target.available_timeslots()).toBe(target.sunday_timeslots)

视图模型:

ready = ->
  # HEALTHFUND.AppointmentViewModel = {}
  HEALTHFUND.AppointmentViewModel = (->
    @date = ko.observable()
    @weekday_timeslots = ['10 am - 12 pm', '12 pm - 2 pm', '2 pm - 4 pm', '4 pm - 6 pm', '6 pm - 9 pm', '9 pm - 12 am']
    @sunday_timeslots = ['12 pm - 2 pm', '2 pm - 4 pm', '4 pm - 6 pm', '6 pm - 8 pm']
    @available_timeslots = ko.computed =>
      input_date = new Date(@date()).getDay()
      if input_date == 0
        return @sunday_timeslots
      else if input_date < 6
        return @weekday_timeslots
      else
        return []
  )()
$(document).ready ready
$(document).on "page:load", ready

实际上只是因为我忘记在视图模型的末尾添加"返回这个"。谢谢!

最新更新