Qunit crashing when used with Date.js
I'm using Qunit and Date.js to test some API functions that I wrote. Here's my code:
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"开发者_Python百科);
});
$.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 keeps crashing on the first test, telling me:
TypeError: Object [object DOMWindow] has no method 'getTime'
And throws out the entire function in the asyncTest. Am I doing something wrong, or is this a bug in Qunit or Date.js?
Using Date objects or passing them around is something that JS (or maybe Date?, don't know really) doesn't seem to like. I changed my function call to:
$.post(createApiUrl("deal/create/1"), {"start_date" : notOkStartDatePast.toISOString(), "end_date" : okEndDate.toISOString() }, function(data) {
equal(data, '{"result" : "fail"}', "The expected error was thrown");
});
I am going to leave the question open for some time in case anyone wants to explain why this works while my original code doesn't.
精彩评论