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中的錯誤?