Skip to content

Commit

Permalink
#2640: moment() instanceof moment fails
Browse files Browse the repository at this point in the history
make the operator instanceof support for moment
  • Loading branch information
alburthoffman committed Oct 5, 2015
1 parent df6789b commit 623d1d2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ moment.defineLocale = defineLocale;
moment.weekdaysShort = weekdaysShort;
moment.normalizeUnits = normalizeUnits;
moment.relativeTimeThreshold = relativeTimeThreshold;
moment.prototype = fn;

export default moment;
28 changes: 28 additions & 0 deletions src/test/moment/instanceof.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { module, test } from '../qunit';
import moment from '../../moment';

module('instanceof');

test('instanceof', function (assert) {
var mm = moment([2010, 0, 1]);

var extend = function (a, b) {
var i;
for (i in b) {
a[i] = b[i];
}
return a;
};

assert.equal(moment() instanceof moment, true, 'simple moment object');
assert.equal(extend({}, moment()) instanceof moment, false, 'extended moment object');
assert.equal(moment(null) instanceof moment, true, 'invalid moment object');

assert.equal(new Date() instanceof moment, false, 'date object is not moment object');
assert.equal(Object instanceof moment, false, 'Object is not moment object');
assert.equal('foo' instanceof moment, false, 'string is not moment object');
assert.equal(1 instanceof moment, false, 'number is not moment object');
assert.equal(NaN instanceof moment, false, 'NaN is not moment object');
assert.equal(null instanceof moment, false, 'null is not moment object');
assert.equal(undefined instanceof moment, false, 'undefined is not moment object');
});

0 comments on commit 623d1d2

Please sign in to comment.