mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Cleanup get/set/unset tests.
This commit is contained in:
54
test/test.js
54
test/test.js
@@ -13066,16 +13066,20 @@
|
|||||||
|
|
||||||
_.each(paths, function(path) {
|
_.each(paths, function(path) {
|
||||||
numberProto.a = 1;
|
numberProto.a = 1;
|
||||||
|
|
||||||
var actual = func(0, path);
|
var actual = func(0, path);
|
||||||
strictEqual(actual, 1);
|
strictEqual(actual, 1);
|
||||||
|
|
||||||
delete numberProto.a;
|
delete numberProto.a;
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(['a.a.a', ['a', 'a', 'a']], function(path) {
|
_.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
|
||||||
stringProto.a = '_';
|
stringProto.replace.b = 1;
|
||||||
|
|
||||||
var actual = func(object, path);
|
var actual = func(object, path);
|
||||||
strictEqual(actual, '_');
|
strictEqual(actual, 1);
|
||||||
delete stringProto.a;
|
|
||||||
|
delete stringProto.replace.b;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -13505,8 +13509,10 @@
|
|||||||
|
|
||||||
_.each(['a', ['a']], function(path) {
|
_.each(['a', ['a']], function(path) {
|
||||||
var actual = func(object, path, 2);
|
var actual = func(object, path, 2);
|
||||||
|
|
||||||
strictEqual(actual, object);
|
strictEqual(actual, object);
|
||||||
strictEqual(object.a, 2);
|
strictEqual(object.a, 2);
|
||||||
|
|
||||||
object.a = 1;
|
object.a = 1;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -13516,8 +13522,10 @@
|
|||||||
|
|
||||||
_.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
_.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||||
var actual = func(object, path, 4);
|
var actual = func(object, path, 4);
|
||||||
|
|
||||||
strictEqual(actual, object);
|
strictEqual(actual, object);
|
||||||
strictEqual(object.a.b.c, 4);
|
strictEqual(object.a.b.c, 4);
|
||||||
|
|
||||||
object.a.b.c = 3;
|
object.a.b.c = 3;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -13527,8 +13535,10 @@
|
|||||||
|
|
||||||
_.each(['a.b.c', ['a.b.c']], function(path) {
|
_.each(['a.b.c', ['a.b.c']], function(path) {
|
||||||
var actual = func(object, path, 4);
|
var actual = func(object, path, 4);
|
||||||
|
|
||||||
strictEqual(actual, object);
|
strictEqual(actual, object);
|
||||||
deepEqual(object, { 'a.b.c': 4 });
|
deepEqual(object, { 'a.b.c': 4 });
|
||||||
|
|
||||||
object['a.b.c'] = 3;
|
object['a.b.c'] = 3;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -13577,9 +13587,11 @@
|
|||||||
|
|
||||||
_.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
|
_.each(['a[1].b.c', ['a', '1', 'b', 'c']], function(path) {
|
||||||
var actual = func(object, path, 4);
|
var actual = func(object, path, 4);
|
||||||
|
|
||||||
strictEqual(actual, object);
|
strictEqual(actual, object);
|
||||||
deepEqual(actual, { 'a': [undefined, { 'b': { 'c': 4 } }] });
|
deepEqual(actual, { 'a': [undefined, { 'b': { 'c': 4 } }] });
|
||||||
ok(!(0 in object.a));
|
ok(!(0 in object.a));
|
||||||
|
|
||||||
delete object.a;
|
delete object.a;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -16109,7 +16121,7 @@
|
|||||||
QUnit.module('lodash.unset');
|
QUnit.module('lodash.unset');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('should unset property on given `object`', 4, function() {
|
test('should unset property values', 4, function() {
|
||||||
_.each(['a', ['a']], function(path) {
|
_.each(['a', ['a']], function(path) {
|
||||||
var object = { 'a': 1, 'c': 2 };
|
var object = { 'a': 1, 'c': 2 };
|
||||||
strictEqual(_.unset(object, path), true);
|
strictEqual(_.unset(object, path), true);
|
||||||
@@ -16117,7 +16129,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should unset deep property on given `object`', 4, function() {
|
test('should unset deep property values', 4, function() {
|
||||||
_.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
_.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||||
var object = { 'a': { 'b': { 'c': null } } };
|
var object = { 'a': { 'b': { 'c': null } } };
|
||||||
strictEqual(_.unset(object, path), true);
|
strictEqual(_.unset(object, path), true);
|
||||||
@@ -16134,7 +16146,6 @@
|
|||||||
_.each(paths, function(path) {
|
_.each(paths, function(path) {
|
||||||
var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
|
var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } };
|
||||||
strictEqual(_.unset(object, path), true);
|
strictEqual(_.unset(object, path), true);
|
||||||
|
|
||||||
ok(!('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f));
|
ok(!('g' in object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -16164,12 +16175,29 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should follow `path` over non-plain objects', 2, function() {
|
test('should follow `path` over non-plain objects', 8, function() {
|
||||||
function Foo() {};
|
var object = { 'a': '' },
|
||||||
Foo.prototype.a = 1;
|
paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
|
||||||
|
|
||||||
strictEqual(_.unset(Foo, 'prototype.a'), true);
|
_.each(paths, function(path) {
|
||||||
strictEqual(Foo.prototype.a, undefined);
|
numberProto.a = 1;
|
||||||
|
|
||||||
|
var actual = _.unset(0, path);
|
||||||
|
strictEqual(actual, true);
|
||||||
|
ok(!('a' in numberProto));
|
||||||
|
|
||||||
|
delete numberProto.a;
|
||||||
|
});
|
||||||
|
|
||||||
|
_.each(['a.replace.b', ['a', 'replace', 'b']], function(path) {
|
||||||
|
stringProto.replace.b = 1;
|
||||||
|
|
||||||
|
var actual = _.unset(object, path);
|
||||||
|
strictEqual(actual, true);
|
||||||
|
ok(!('a' in stringProto.replace));
|
||||||
|
|
||||||
|
delete stringProto.replace.b;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `false` for non-configurable properties', 1, function() {
|
test('should return `false` for non-configurable properties', 1, function() {
|
||||||
@@ -16178,7 +16206,7 @@
|
|||||||
if (defineProperty) {
|
if (defineProperty) {
|
||||||
defineProperty(object, 'a', {
|
defineProperty(object, 'a', {
|
||||||
'configurable': false,
|
'configurable': false,
|
||||||
'value': null
|
'value': 1
|
||||||
});
|
});
|
||||||
strictEqual(_.unset(object, 'a'), false);
|
strictEqual(_.unset(object, 'a'), false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user