HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/rest/node_modules/merge-defaults/test/compatibility.test.js
var _ = require('@sailshq/lodash');
var should = require('should');
_.defaultsDeep = require('../');



/**
 * Purpose:
 * This test exists to make sure I didn't break anything when
 * using mergeDefaults to override `_.defaults`.
 */

// From Lodash core tests:
// https://github.com/lodash/lodash/blob/master/test/test.js#L1843
describe('Test that _.mergeDefaults is backwards compatible with _.defaults \n', function() {
  it('should assign properties of a source object if missing on the destination object', function() {
    deepEqual(_.defaultsDeep({
      'a': 1
    }, {
      'a': 2,
      'b': 2
    }), {
      'a': 1,
      'b': 2
    });
  });

  it('should assign own source properties', function() {
    function Foo() {
      this.a = 1;
      this.c = 3;
    }

    Foo.prototype.b = 2;
    deepEqual(_.defaultsDeep({
      'c': 2
    }, new Foo()), {
      'a': 1,
      'c': 2
    });
  });

  it('should accept multiple source objects', function() {
    var expected = {
      'a': 1,
      'b': 2,
      'c': 3
    };
    deepEqual(_.defaultsDeep({
      'a': 1,
      'b': 2
    }, {
      'b': 3
    }, {
      'c': 3
    }), expected);
    deepEqual(_.defaultsDeep({
      'a': 1,
      'b': 2
    }, {
      'b': 3,
      'c': 3
    }, {
      'c': 2
    }), expected);
  });

  it('should not overwrite `null` values', function() {
    var actual = _.defaultsDeep({
      'a': null
    }, {
      'a': 1
    });
    strictEqual(actual.a, null);
  });

  it('should overwrite `undefined` values', function() {
    var actual = _.defaultsDeep({
      'a': undefined
    }, {
      'a': 1
    });
    strictEqual(actual.a, 1);
  });

  it('should not error on `null` or `undefined` sources (test in IE < 9)', function() {
    try {
      deepEqual(_.defaultsDeep({
        'a': 1
      }, null, undefined, {
        'a': 2,
        'b': 2
      }), {
        'a': 1,
        'b': 2
      });
    } catch (e) {
      throw e;
    }
  });
});


// helper methods
function strictEqual(x, y) {
  return should(x).equal(y);
}

function deepEqual(x, y) {
  return should(x).eql(y);
}