????????

???????????????????????????ж??????????????????????????????(?????????????AssertionError ??)??????????????????????????????????“??”??????????????????????????????????????

????[javascript] view plaincopy1. assert("Small date difference expected '3 days?? 2 hours?? 16 minutes and " +

????2. "10 seconds ago' got '" + element.text() + "'"??

????3. element.text() == "3 days?? 2 hours?? 16 minutes and 10 seconds ago");

????????????????????????????????????????????????????????????????????(????The idea is thattesting is about stating your expectations upfront?? and the assertion resemblesa specification with the leading message.)??

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????assertEquals??(Most testframeworks have something along the lines of assertEquals for thisspecific use case.)

????[javascript] view plaincopy1. assertEquals("3 days?? 2 hours?? 16 minutes and 10 seconds ago"?? element.text());

?????????????????????????assertEquals ??????????????????????????????????????????????????????????????????

??????????????setUp ?? tearDown

??????????????????????У?????????????????????????ò?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????JsTestDriver????????????????????????????????

????[javascript] view plaincopy1. var second = 1000;

????2. var minute = 60 * second;

????3. var hour = 60 * minute;

????4. var day = 24 * hour;

????5.

????6. TestCase("TimeDifferenceInWordsTest"?? {

????7. "test 8 day difference should result in '1 week ago'": function () {

????8. var dateStr = new Date(new Date() - 8 * day).toString();

????9. var element = jQuery('Replace me');

????10. element.differenceInWords();

????11.

????12. assertEquals("1 week ago"?? element.text());

????13. }??

????14.

????15. "test should display difference with days?? hours?? minutes and seconds": function () {

????16. var diff = 3 * day + 2 * hour + 16 * minute + 10 * second;

????17. dateStr = new Date(new Date() - diff).toString();

????18. var element = jQuery('Replace me');

????19. element.differenceInWords();

????20.

????21. assertEquals("3 days?? 2 hours?? 16 minutes and 10 seconds ago"?? element.text());

????22. }

????23. });

?????????????????????????????????????????????????????????????????????????????????????????setUp?????????????????????????setUp??????????????????????á?

????[javascript] view plaincopy1. TestCase("TimeDifferenceInWordsTest"?? {

????2. setUp: function () {

????3. this.date8DaysAgo = new Date(new Date() - 8 * day);

????4. var diff = 3 * day + 2 * hour + 16 * minute + 10 * second;

????5. this.date3DaysAgo = new Date(new Date() - diff);

????6. }??

????7.

????8. "test 8 day difference should result in '1 week ago'": function () {

????9. var element = jQuery('Replace me');

????10. element.differenceInWords();

????11.

????12. assertEquals("1 week ago"?? element.text());

????13. }??

????14.

????15. "test should display difference with days?? hours?? minutes and seconds": function () {

????16. var element = jQuery('Replace me');

????17. element.differenceInWords();

????18.

????19. assertEquals("3 days?? 2 hours?? 16 minutes and 10 seconds ago"?? element.text());

????20. }

????21. });

????setUp ????????????????tearDown ????????????????????С????????????tearDown ????????????????κ?????????????????????????????????tearDown ??????????????localStorage???????Щ????????????????????????棬??????????????????????д??localStorage ?е??????????

???????????????????????????????????в????????????JavaScript???????????????????HTML??????????????????????????(??????????????)?????HTML???????????????????С???????е?????????????????????????????в??????

???????????????????????

?????????????????????????????????????????????????????????????????????????????????????????????????и????????????????????а????????HTML????????????????????????????web???????????????????м?????????????????????????????ò?????????3??????????5??????????????2???????°汾?????????????????HTML??????????????????