2014-03-27 80 views
0

測試自定義事件我想測試changeDate事件我bootstrap datepicker的:如何通過傳遞操縱事件對象

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

回答

0

想通了:

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)); 
}); 

的伎倆。