vendredi 6 mai 2016

Checking date format in Karma Jasmine unit test case

I'm having a logic that converts date to new Date()

$scope.isValidatStartDate=function("2016-05-04")
{
   var dateList = date.split("-");
   $scope..endMaxDate = new Date(dateList[0], dateList[1] - 1, dateList[2]);
}

I have written test case to check whether the passed date is in the format of new Date();

  it("Expect date should be validated", function () {
            var date = "2016-05-04";
            scope.isValidatStartDate(date);
            expect(scope.endMaxDate).toBe("Wed May 04 2016 00:00:00 GMT+0530 (India Standard Time)");
        });

But the test is failing as the message in the Karma debugger console says..

debug.html:38 Expected Date(Wed May 04 2016 00:00:00 GMT+0530 (India Standard Time)) to be 'Wed May 04 2016 00:00:00 GMT+0530 (India Standard Time)'.

The test expects Date object to be string.Hence it is failing.How can I check instead of string if the date object is really a date object?

Aucun commentaire:

Enregistrer un commentaire