I use buster.js and I want to test a function returning the age of a person from her year of birth. My test look like this:
"Should get correct age from year": function () {
assert(getAgeFromYear(1990) === 22);
}
This will only stay green until the end of 2012. How can I fake the date object in buster.js so that it will be valid in the next years?
Make a function
getAgeFromYearDate(int, Date)and test that. Then make a functiongetAgeFromYear(int)which uses the current Date. That method will look like this:If
getAgeFromYearDateworks correctly, you can assume thatgetAgeFromYearworks correctly.