1'use strict'; 2require('../common'); 3const assert = require('assert'); 4 5// Disable colored output to prevent color codes from breaking assertion 6// message comparisons. This should only be an issue when process.stdout 7// is a TTY. 8if (process.stdout.isTTY) 9 process.env.NODE_DISABLE_COLORS = '1'; 10 11// Turn off no-restricted-properties because we are testing deepEqual! 12/* eslint-disable no-restricted-properties */ 13 14// See https://github.com/nodejs/node/issues/10258 15{ 16 const date = new Date('2016'); 17 function FakeDate() {} 18 FakeDate.prototype = Date.prototype; 19 const fake = new FakeDate(); 20 21 assert.notDeepEqual(date, fake); 22 assert.notDeepEqual(fake, date); 23 24 // For deepStrictEqual we check the runtime type, 25 // then reveal the fakeness of the fake date 26 assert.throws( 27 () => assert.deepStrictEqual(date, fake), 28 { 29 message: 'Expected values to be strictly deep-equal:\n' + 30 '+ actual - expected\n\n+ 2016-01-01T00:00:00.000Z\n- Date {}' 31 } 32 ); 33 assert.throws( 34 () => assert.deepStrictEqual(fake, date), 35 { 36 message: 'Expected values to be strictly deep-equal:\n' + 37 '+ actual - expected\n\n+ Date {}\n- 2016-01-01T00:00:00.000Z' 38 } 39 ); 40} 41 42{ // At the moment global has its own type tag 43 const fakeGlobal = {}; 44 Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(global)); 45 for (const prop of Object.keys(global)) { 46 fakeGlobal[prop] = global[prop]; 47 } 48 assert.notDeepEqual(fakeGlobal, global); 49 // Message will be truncated anyway, don't validate 50 assert.throws(() => assert.deepStrictEqual(fakeGlobal, global), 51 assert.AssertionError); 52} 53 54{ // At the moment process has its own type tag 55 const fakeProcess = {}; 56 Object.setPrototypeOf(fakeProcess, Object.getPrototypeOf(process)); 57 for (const prop of Object.keys(process)) { 58 fakeProcess[prop] = process[prop]; 59 } 60 assert.notDeepEqual(fakeProcess, process); 61 // Message will be truncated anyway, don't validate 62 assert.throws(() => assert.deepStrictEqual(fakeProcess, process), 63 assert.AssertionError); 64} 65/* eslint-enable */ 66