From d08df925a5e5c132b366957567c484724a29cd12 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Mon, 13 Jan 2014 23:16:24 -0800 Subject: [PATCH] Add tests for weird moment clones --- test/moment/create.js | 15 +++++++++++++++ test/moment/is_moment.js | 12 ++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/test/moment/create.js b/test/moment/create.js index 6baf65f7b..d65de741e 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -105,6 +105,21 @@ exports.create = { test.done(); }, + "cloning moment works with weird clones" : function (test) { + var extend = function(a, b) { + var i; + for (i in b) { + a[i] = b[i]; + } + return a; + }, + now = moment(); + + test.expect(1); + test.equal(+extend({}, now).clone(), +now, "cloning extend-ed now is now"); + test.done(); + }, + "undefined" : function (test) { test.expect(1); test.ok(moment().toDate() instanceof Date, "undefined"); diff --git a/test/moment/is_moment.js b/test/moment/is_moment.js index 1fb49bcda..697270926 100644 --- a/test/moment/is_moment.js +++ b/test/moment/is_moment.js @@ -2,15 +2,23 @@ var moment = require('../../moment'); exports.is_moment = { "is moment object": function (test) { - test.expect(11); + test.expect(12); - var MyObj = function () {}; + var MyObj = function () {}, + extend = function(a, b) { + var i; + for (i in b) { + a[i] = b[i]; + } + return a; + }; MyObj.prototype.toDate = function () { return new Date(); }; test.ok(moment.isMoment(moment()), 'simple moment object'); test.ok(moment.isMoment(moment('invalid date')), 'invalid moment object'); + test.ok(moment.isMoment(extend({}, moment())), 'externally cloned moments are moments'); test.ok(!moment.isMoment(new MyObj()), 'myObj is not moment object'); test.ok(!moment.isMoment(moment), 'moment function is not moment object'); -- 2.47.2