HTML and CSS Reference
In-Depth Information
output("<strong>" + testCount + " tests, " +
(testCount - successful) + " failures</strong>",
color);
}
Listing 1.11 uses testCase to restructure the strftime test into a test case.
Listing 1.11 strftime test case
var date = new Date(2009, 9, 2);
testCase("strftime test", {
"test format specifier %Y": function () {
assert("%Y should return full year",
date.strftime("%Y") === "2009");
},
"test format specifier %m": function () {
assert("%m should return month",
date.strftime("%m") === "10");
},
"test format specifier %d": function () {
assert("%d should return date",
date.strftime("%d") === "02");
},
"test format specifier %y": function () {
assert("%y should return year as two digits",
date.strftime("%y") === "09");
},
"test format shorthand %F": function () {
assert("%F should act as %Y-%m-%d",
date.strftime("%F") === "2009-10-02");
}
});
The tests have so far been distinct and simple enough that we end up with one
assertion in each test. The test case now groups all the tests into a single object, but
the date object is still being created outside, which is unnatural as it's an integral
part of the test. We could create a new object inside each test, but since we can
create it the same way for all of them, that would lead to unnecessary duplication.
A better option would be to gather common setup code in a single place.
 
Search WWH ::




Custom Search