Skip to content

Commit 1b66d90

Browse files
committed
[Tests] add tests for getters, fake arrays, overriding getTime on Dates
1 parent a159a3a commit 1b66d90

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

test/cmp.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test('arguments class', function (t) {
8989
t.end();
9090
});
9191

92-
test('dates', function (t) {
92+
test('Dates', function (t) {
9393
var d0 = new Date(1387585278000);
9494
var d1 = new Date('Fri Dec 20 2013 16:21:18 GMT-0800 (PST)');
9595

@@ -99,6 +99,14 @@ test('dates', function (t) {
9999

100100
t.deepEqualTest(d0, d1, 'two Dates with the same timestamp but different own properties', false, false);
101101

102+
t.test('overriding `getTime`', { skip: !Object.defineProperty }, function (st) {
103+
var a = new Date('2000');
104+
var b = new Date('2000');
105+
Object.defineProperty(a, 'getTime', { value: function () { return 5; } });
106+
st.deepEqualTest(a, b, 'two Dates with the same timestamp but one has overridden `getTime`', true, true);
107+
st.end();
108+
});
109+
102110
t.end();
103111
});
104112

@@ -443,3 +451,38 @@ test('boxed primitives', function (t) {
443451

444452
t.end();
445453
});
454+
455+
test('getters', { skip: !Object.defineProperty }, function (t) {
456+
var a = {};
457+
Object.defineProperty(a, 'a', { enumerable: true, get: function () { return 5; } });
458+
var b = {};
459+
Object.defineProperty(b, 'a', { enumerable: true, get: function () { return 6; } });
460+
461+
t.deepEqualTest(a, b, 'two objects with the same getter but producing different values', false, false);
462+
463+
t.end();
464+
});
465+
466+
// eslint-disable-next-line no-proto
467+
test('fake arrays: extra keys will be tested', { skip: [].__proto__ !== Array.prototype }, function (t) {
468+
var a = {
469+
__proto__: Array.prototype,
470+
0: 1,
471+
1: 1,
472+
2: 'broken',
473+
length: 2
474+
};
475+
if (hasSymbols) {
476+
Object.defineProperty(a, Symbol.toStringTag, {
477+
value: 'Array'
478+
});
479+
}
480+
if (Object.defineProperty) {
481+
Object.defineProperty(a, 'length', {
482+
enumerable: false
483+
});
484+
}
485+
486+
t.deepEqualTest(a, [1, 1], 'fake and real array with same contents and [[Prototype]]', false, false);
487+
t.end();
488+
});

0 commit comments

Comments
 (0)