Files
lodash/test/defaults.test.js
Benjamin Tan d5ef31929a Add initial test files from lodash v4. (#4172)
* Install test dependencies.

* Add initial test files.

These files were created using a simplistic AST manipulator using `recast` to
preserve formatting. There's bound to be a huge chunk of errors, but this serves
as a good start. QUnit was replaced with Mocha, with ES2015 imports running via
`esm`.

As far as possible, QUnit-specific syntax has been replaced with Mocha's
`describe` and `it`, while the native Node.js `assert` module is used for
assertions. Files in the `test` directory ending in `.test.js` will be treated
as test files.

* Add initial passing files to test run.
2019-02-12 09:11:32 -08:00

67 lines
2.1 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { objectProto } from './utils.js';
import defaults from '../defaults.js';
describe('defaults', function() {
it('should assign source properties if missing on `object`', function() {
var actual = defaults({ 'a': 1 }, { 'a': 2, 'b': 2 });
assert.deepStrictEqual(actual, { 'a': 1, 'b': 2 });
});
it('should accept multiple sources', function() {
var expected = { 'a': 1, 'b': 2, 'c': 3 },
actual = defaults({ 'a': 1, 'b': 2 }, { 'b': 3 }, { 'c': 3 });
assert.deepStrictEqual(actual, expected);
actual = defaults({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 3 }, { 'c': 2 });
assert.deepStrictEqual(actual, expected);
});
it('should not overwrite `null` values', function() {
var actual = defaults({ 'a': null }, { 'a': 1 });
assert.strictEqual(actual.a, null);
});
it('should overwrite `undefined` values', function() {
var actual = defaults({ 'a': undefined }, { 'a': 1 });
assert.strictEqual(actual.a, 1);
});
it('should assign `undefined` values', function() {
var source = { 'a': undefined, 'b': 1 },
actual = defaults({}, source);
assert.deepStrictEqual(actual, { 'a': undefined, 'b': 1 });
});
it('should assign properties that shadow those on `Object.prototype`', function() {
var object = {
'constructor': objectProto.constructor,
'hasOwnProperty': objectProto.hasOwnProperty,
'isPrototypeOf': objectProto.isPrototypeOf,
'propertyIsEnumerable': objectProto.propertyIsEnumerable,
'toLocaleString': objectProto.toLocaleString,
'toString': objectProto.toString,
'valueOf': objectProto.valueOf
};
var source = {
'constructor': 1,
'hasOwnProperty': 2,
'isPrototypeOf': 3,
'propertyIsEnumerable': 4,
'toLocaleString': 5,
'toString': 6,
'valueOf': 7
};
var expected = lodashStable.clone(source);
assert.deepStrictEqual(defaults({}, source), expected);
expected = lodashStable.clone(object);
assert.deepStrictEqual(defaults({}, object, source), expected);
});
});