mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
Add _.matches and _.matchesProperty tests for primitive object and a source with undefined values.
This commit is contained in:
55
test/test.js
55
test/test.js
@@ -9596,6 +9596,33 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should handle a primitive `object` and a `source` with `undefined` values', 3, function() {
|
||||||
|
numberProto.a = 1;
|
||||||
|
numberProto.b = undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var matches = _.matches({ 'b': undefined });
|
||||||
|
strictEqual(matches(1), true);
|
||||||
|
} catch(e) {
|
||||||
|
ok(false, e.message);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
matches = _.matches({ 'a': 1, 'b': undefined });
|
||||||
|
strictEqual(matches(1), true);
|
||||||
|
} catch(e) {
|
||||||
|
ok(false, e.message);
|
||||||
|
}
|
||||||
|
numberProto.a = { 'b': 1, 'c': undefined };
|
||||||
|
try {
|
||||||
|
matches = _.matches({ 'a': { 'c': undefined } });
|
||||||
|
strictEqual(matches(1), true);
|
||||||
|
} catch(e) {
|
||||||
|
ok(false, e.message);
|
||||||
|
}
|
||||||
|
delete numberProto.a;
|
||||||
|
delete numberProto.b;
|
||||||
|
});
|
||||||
|
|
||||||
test('should match properties when `value` is a function', 1, function() {
|
test('should match properties when `value` is a function', 1, function() {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
Foo.a = { 'b': 1, 'c': 2 };
|
Foo.a = { 'b': 1, 'c': 2 };
|
||||||
@@ -9887,7 +9914,7 @@
|
|||||||
deepEqual(actual, [objects[0]]);
|
deepEqual(actual, [objects[0]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle a `value` with `undefined` values', 3, function() {
|
test('should handle a `value` with `undefined` values', 2, function() {
|
||||||
var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
|
var objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }],
|
||||||
matches = _.matchesProperty('b', undefined),
|
matches = _.matchesProperty('b', undefined),
|
||||||
actual = _.map(objects, matches),
|
actual = _.map(objects, matches),
|
||||||
@@ -9896,17 +9923,33 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
|
|
||||||
objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
|
objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }];
|
||||||
matches = _.matchesProperty('a', { 'a': 1, 'b': undefined });
|
|
||||||
actual = _.map(objects, matches);
|
|
||||||
|
|
||||||
deepEqual(actual, expected);
|
|
||||||
|
|
||||||
matches = _.matchesProperty('a', { 'b': undefined });
|
matches = _.matchesProperty('a', { 'b': undefined });
|
||||||
actual = _.map(objects, matches);
|
actual = _.map(objects, matches);
|
||||||
|
|
||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should handle a primitive `object` and a `source` with `undefined` values', 2, function() {
|
||||||
|
numberProto.a = 1;
|
||||||
|
numberProto.b = undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var matches = _.matchesProperty('b', undefined);
|
||||||
|
strictEqual(matches(1), true);
|
||||||
|
} catch(e) {
|
||||||
|
ok(false, e.message);
|
||||||
|
}
|
||||||
|
numberProto.a = { 'b': 1, 'c': undefined };
|
||||||
|
try {
|
||||||
|
matches = _.matchesProperty('a', { 'c': undefined });
|
||||||
|
strictEqual(matches(1), true);
|
||||||
|
} catch(e) {
|
||||||
|
ok(false, e.message);
|
||||||
|
}
|
||||||
|
delete numberProto.a;
|
||||||
|
delete numberProto.b;
|
||||||
|
});
|
||||||
|
|
||||||
test('should work with a function for `value`', 1, function() {
|
test('should work with a function for `value`', 1, function() {
|
||||||
function source() {}
|
function source() {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user