0

我想测试我的引导 datepickerchangeDate的事件:

elem.on('changeDate', function(event) {
    var newVal = event.date;
    ...
});

茉莉花:

it('sets a new startDate', function() {
    elem.trigger('changeDate', {date: new Date(2014, 1, 2)});
    expect(elem.datepicker('getDate')).toEqual(new Date(2014, 1, 2));
});

记录时event,会返回整个日期选择器object,但date仍然是undefined. 我应该如何通过我的自定义测试date

4

1 回答 1

1

弄清楚了:

it('sets a new startDate', function() {
    var event = jQuery.Event('changeDate');
    event.date = new Date(2014, 1, 2);
    elem.trigger(event);
    expect(elem.datepicker('getDate')).toEqual(new Date(2014, 1, 2));
});

成功了。

于 2014-03-27T09:50:30.957 回答