I waited to respond because I am not certain that there are no Date test suites already out there for javascript. I wanted to give the benefit of the doubt to anyone who might know more.
However, as far as I know this sort of testing would all be done in browser building/validation. It certainly is possible to use some of the existing test suites from that realm of development, but I don't think it would be an easy task to set-up. Many of the browser's have a build process that you could fork (specifically you could isolate their date test cases). Within their test process you would have to find the given segment for Javascript Date objects, that would test to ensure w3 spec compatibility.
At that, Selenium is a very common and practical means of creating unit tests and if designed well integration tests for web-apps (hooking into the javascript as well), and is capable of producing nice reports on test results.
Lastly, a cummulative post on Javascript Testing libraries can be found on this post about Javascript TDD (Test Driven Design)
Or you could do something like the following (meant to be a guideline not a complete solution -- inspired by the comment from dandavis):
var epochTS = 0;
var bd = new BardyDate(epochTS);
var d = new Date(epochTS);
Object.getOwnPropertyNames(Date.prototype).forEach(function(dateFunction){
//in this if statement you are testing the functions like getTime() and getYear()
if(dateFunction.indexOf("get") == 0){
console.log("dateFunction " + dateFunction +
"() pass: " + (bd[dateFunction]() === d[dateFunction]()))
}
//in this if statement you are testing the functions like toString() and toJSON()
if(dateFunction.indexOf("to") == 0){
console.log("dateFunction " + dateFunction +
"() pass: " + (bd[dateFunction]() === d[dateFunction]()))
}
//then there are the 16 set methods, those you probably would want to hardcode.
//unless you are content with passing a hard coded value in like "10" -- the
//issue would be bounds testing, which you would likely want to hardcode.
//beyond the scope of this for-each loop.
})
A little explanation on the above snippet
With Object.getOwnPropertNames(Date.prototype)
you can obtain all the methods of Date
despite the fact that Date
has the property DontEnum (see this post for more info).
Also you are able to treat each function string as a key within the javascript object hence the d[dateFunction]()
which if dateFunction === "toString"
would be interpreted/compiled down to d[toString]()
which is equivalent to d.toString()