From eaca7e6d12b36626e978636ab524f2b4bd2235e2 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Thu, 24 May 2012 09:51:09 -0700 Subject: [PATCH] Adding tests for isValid and moment.utc() --- test/moment/is_valid.js | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/test/moment/is_valid.js b/test/moment/is_valid.js index c3bafa0d9..2934128eb 100644 --- a/test/moment/is_valid.js +++ b/test/moment/is_valid.js @@ -1,7 +1,7 @@ var moment = require("../../moment"); exports.is_valid = { - "array bad month" : function(test) { + "array bad month" : function (test) { test.expect(2); test.equal(moment([2010, -1]).isValid(), false, 'month -1'); @@ -10,43 +10,53 @@ exports.is_valid = { test.done(); }, - "array good month" : function(test) { - test.expect(12); + "array good month" : function (test) { + test.expect(24); for (var i = 0; i < 12; i++) { test.equal(moment([2010, i]).isValid(), true, 'month ' + i); + test.equal(moment.utc([2010, i]).isValid(), true, 'month ' + i); } test.done(); }, - "array bad date" : function(test) { - test.expect(2); + "array bad date" : function (test) { + test.expect(4); test.equal(moment([2010, 0, 0]).isValid(), false, 'date 0'); test.equal(moment([2100, 0, 32]).isValid(), false, 'date 32'); + test.equal(moment.utc([2010, 0, 0]).isValid(), false, 'utc date 0'); + test.equal(moment.utc([2100, 0, 32]).isValid(), false, 'utc date 32'); + test.done(); }, - "array bad date leap year" : function(test) { - test.expect(4); + "array bad date leap year" : function (test) { + test.expect(8); test.equal(moment([2010, 1, 29]).isValid(), false, '2010 feb 29'); test.equal(moment([2100, 1, 29]).isValid(), false, '2100 feb 29'); test.equal(moment([2008, 1, 30]).isValid(), false, '2008 feb 30'); test.equal(moment([2000, 1, 30]).isValid(), false, '2000 feb 30'); + + test.equal(moment.utc([2010, 1, 29]).isValid(), false, 'utc 2010 feb 29'); + test.equal(moment.utc([2100, 1, 29]).isValid(), false, 'utc 2100 feb 29'); + test.equal(moment.utc([2008, 1, 30]).isValid(), false, 'utc 2008 feb 30'); + test.equal(moment.utc([2000, 1, 30]).isValid(), false, 'utc 2000 feb 30'); + test.done(); }, - "string nonsensical" : function(test) { + "string nonsensical" : function (test) { test.expect(1); test.equal(moment('fail').isValid(), false, 'string "fail"'); test.done(); }, - "invalid string iso 8601" : function(test) { + "invalid string iso 8601" : function (test) { var tests = [ '2010-00-00', @@ -57,15 +67,16 @@ exports.is_valid = { '2010-01-01T23:59:60' ]; - test.expect(tests.length); + test.expect(tests.length * 2); for (var i = 0; i < tests.length; i++) { test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid'); + test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid'); } test.done(); }, - "invalid string iso 8601 + timezone" : function(test) { + "invalid string iso 8601 + timezone" : function (test) { var tests = [ '2010-00-00+00:00', @@ -77,15 +88,16 @@ exports.is_valid = { '2010-01-40T23:59:59.9999+00:00' ]; - test.expect(tests.length); + test.expect(tests.length * 2); for (var i = 0; i < tests.length; i++) { test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid'); + test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid'); } test.done(); }, - "valid string iso 8601 + timezone" : function(test) { + "valid string iso 8601 + timezone" : function (test) { var tests = [ '2010-01-01', '2010-01-30', @@ -95,10 +107,11 @@ exports.is_valid = { '2010-01-30T23:59:59.999+00:00' ]; - test.expect(tests.length); + test.expect(tests.length * 2); for (var i = 0; i < tests.length; i++) { test.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid'); + test.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid'); } test.done(); } -- 2.47.2