我想测试bootstrap datepicker的changeDate
事件:
elem.on('changeDate', function(event) {
var newVal = event.date;
...
});
与Jasmine:
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
?
答案 0 :(得分: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));
});
诀窍。