]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix fragile utc default time test 1351/head
authorpimterry <pimterry@gmail.com>
Wed, 11 Dec 2013 21:18:09 +0000 (21:18 +0000)
committerpimterry <pimterry@gmail.com>
Wed, 11 Dec 2013 21:20:26 +0000 (21:20 +0000)
test/moment/utc.js

index 0239efff9aecdc7aa72b65017cbd8df04848016f..09c2de1a5ef0ce9d2ff9d0c247647816853d8eed 100644 (file)
@@ -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");