From: pimterry Date: Wed, 11 Dec 2013 21:18:09 +0000 (+0000) Subject: Fix fragile utc default time test X-Git-Tag: 2.5.0^2~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a55b4b37aa4d01df8a87a3d28b3a486da07f559;p=thirdparty%2Fmoment.git Fix fragile utc default time test --- diff --git a/test/moment/utc.js b/test/moment/utc.js index 0239efff9..09c2de1a5 100644 --- a/test/moment/utc.js +++ b/test/moment/utc.js @@ -34,19 +34,27 @@ exports.utc = { expected = (24 + 3 - zone) % 24; test.equal(m.hours(), expected, "the hours (" + m.hours() + ") should be correct for local"); test.equal(moment().utc().zone(), 0, "timezone in utc should always be zero"); + test.done(); }, - "creating with utc" : function (test) { - test.expect(7); + "creating with utc and no arguments" : function (test) { + test.expect(2); + + var startOfTest = new Date().valueOf(), + momentDefaultUtcTime = moment.utc().valueOf(), + afterMomentCreationTime = new Date().valueOf(); - var diff = moment.utc().valueOf() - moment().valueOf(), m; - diff = Math.abs(diff); - // we check the diff rather than equality because sometimes they are off by a millisecond + test.ok(startOfTest <= momentDefaultUtcTime, "moment UTC default time should be now, not in the past"); + test.ok(momentDefaultUtcTime <= afterMomentCreationTime, "moment UTC default time should be now, not in the future"); + + test.done(); + }, - test.ok(diff < 5, "Calling moment.utc() should default to the current time"); + "creating with utc and a date parameter array" : function (test) { + test.expect(6); - m = moment.utc([2011, 1, 2, 3, 4, 5, 6]); + var m = moment.utc([2011, 1, 2, 3, 4, 5, 6]); test.equal(m.date(), 2, "the day should be correct for utc array"); test.equal(m.hours(), 3, "the hours should be correct for utc array");