2011-09-16 57 views
1

我正在使用Qunit和Date.js來測試我編寫的一些API函數。這裏是我的代碼:Qunit在與Date.js一起使用時崩潰

asyncTest("createDeal", 4, function() { 
    var okStartDate = Date.today().addDays(4), 
     notOkStartDatePast = Date.today().addDays(-1), 
     notOkStartDateFuture = Date.today().addDays(1), 
     okEndDate, 
     notOkEndDateForOkStartDate; 

     okEndDate = okStartDate.addDays(8); 
     notOkEndDateForOkStartDate = okStartDate.addDays(1); 

    $.post(createApiUrl("deal/create/1"), {"start_date" : okStartDate, "end_date" : notOkEndDateForOkStartDate}, function(data) { 
     equal(data, '{"result":"fail"}', "The expected error was thrown"); 
    }); 

    $.post(createApiUrl("deal/create/1"), {"start_date" : notOkStartDatePast, "end_date" : okEndDate }, function(data) { 
     equal(data, '{"result" : "fail"}', "The expected error was thrown"); 
    }); 

    $.post(createApiUrl("deal/create/1"), {"start_date" : notOkStartDateFuture, "end_date" : okEndDate }, function(data) { 
     equal(data, '{"result" : "fail"}', "The expected error was thrown"); 
    }); 

    $.post(createApiUrl("deal/create/1"), {"start_date" : okStartDate, "end_date" : okEndDate }, function(data) { 
     equal(data, '{"result" : "success"}', "Params passed in were OK. Query ran OK."); 

     start(); 
    }); 
}); 

Qunit總是崩潰第一次測試,告訴我:

TypeError: Object [object DOMWindow] has no method 'getTime' 

,並引發了在asyncTest整個功能。我做錯了什麼,或者這是Qunit或Date.js中的錯誤?

回答

0

使用Date對象或路過他們身邊的東西,JS(或者日期?真的不知道),似乎並不喜歡。我改變了我的函數調用:

$.post(createApiUrl("deal/create/1"), {"start_date" : notOkStartDatePast.toISOString(), "end_date" : okEndDate.toISOString() }, function(data) { 
     equal(data, '{"result" : "fail"}', "The expected error was thrown"); 
    }); 

我要離開這個問題開了一段時間,以防有人想解釋爲什麼這工作,而我的原代碼沒有。

相關問題