mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* 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.
70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { args, toArgs, objectProto, stringProto } from './utils.js';
|
|
import omit from '../omit.js';
|
|
|
|
describe('omit', function() {
|
|
var args = toArgs(['a', 'c']),
|
|
object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 },
|
|
nested = { 'a': 1, 'b': { 'c': 2, 'd': 3 } };
|
|
|
|
it('should flatten `paths`', function() {
|
|
assert.deepStrictEqual(omit(object, 'a', 'c'), { 'b': 2, 'd': 4 });
|
|
assert.deepStrictEqual(omit(object, ['a', 'd'], 'c'), { 'b': 2 });
|
|
});
|
|
|
|
it('should support deep paths', function() {
|
|
assert.deepStrictEqual(omit(nested, 'b.c'), { 'a': 1, 'b': { 'd': 3} });
|
|
});
|
|
|
|
it('should support path arrays', function() {
|
|
var object = { 'a.b': 1, 'a': { 'b': 2 } },
|
|
actual = omit(object, [['a.b']]);
|
|
|
|
assert.deepStrictEqual(actual, { 'a': { 'b': 2 } });
|
|
});
|
|
|
|
it('should omit a key over a path', function() {
|
|
var object = { 'a.b': 1, 'a': { 'b': 2 } };
|
|
|
|
lodashStable.each(['a.b', ['a.b']], function(path) {
|
|
assert.deepStrictEqual(omit(object, path), { 'a': { 'b': 2 } });
|
|
});
|
|
});
|
|
|
|
it('should coerce `paths` to strings', function() {
|
|
assert.deepStrictEqual(omit({ '0': 'a' }, 0), {});
|
|
});
|
|
|
|
it('should return an empty object when `object` is nullish', function() {
|
|
lodashStable.each([null, undefined], function(value) {
|
|
objectProto.a = 1;
|
|
var actual = omit(value, 'valueOf');
|
|
delete objectProto.a;
|
|
assert.deepStrictEqual(actual, {});
|
|
});
|
|
});
|
|
|
|
it('should work with a primitive `object`', function() {
|
|
stringProto.a = 1;
|
|
stringProto.b = 2;
|
|
|
|
assert.deepStrictEqual(omit('', 'b'), { 'a': 1 });
|
|
|
|
delete stringProto.a;
|
|
delete stringProto.b;
|
|
});
|
|
|
|
it('should work with `arguments` object `paths`', function() {
|
|
assert.deepStrictEqual(omit(object, args), { 'b': 2, 'd': 4 });
|
|
});
|
|
|
|
it('should not mutate `object`', function() {
|
|
lodashStable.each(['a', ['a'], 'a.b', ['a.b']], function(path) {
|
|
var object = { 'a': { 'b': 2 } };
|
|
omit(object, path);
|
|
assert.deepStrictEqual(object, { 'a': { 'b': 2 } });
|
|
});
|
|
});
|
|
});
|