mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Ensure _.match and _.matchesProperty compares functions by reference. [closes #1101]
This commit is contained in:
@@ -2342,8 +2342,8 @@
|
||||
othIsArr = isTypedArray(other);
|
||||
}
|
||||
}
|
||||
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)) && !isHostObject(object),
|
||||
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)) && !isHostObject(other),
|
||||
var objIsObj = objTag == objectTag && !isHostObject(object),
|
||||
othIsObj = othTag == objectTag && !isHostObject(other),
|
||||
isSameTag = objTag == othTag;
|
||||
|
||||
if (isSameTag && !(objIsArr || objIsObj)) {
|
||||
|
||||
36
test/test.js
36
test/test.js
@@ -9402,6 +9402,17 @@
|
||||
strictEqual(matches(object2), false);
|
||||
});
|
||||
|
||||
test('should compare functions by reference', 3, function() {
|
||||
var object1 = { 'a': _.noop },
|
||||
object2 = { 'a': noop },
|
||||
object3 = { 'a': {} },
|
||||
matches = _.matches(object1);
|
||||
|
||||
strictEqual(matches(object1), true);
|
||||
strictEqual(matches(object2), false);
|
||||
strictEqual(matches(object3), false);
|
||||
});
|
||||
|
||||
test('should not change match behavior if `source` is augmented', 9, function() {
|
||||
_.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
|
||||
var object = _.cloneDeep(source),
|
||||
@@ -9524,9 +9535,7 @@
|
||||
|
||||
test('should match properties when `value` is a function', 1, function() {
|
||||
function Foo() {}
|
||||
Foo.a = function() {};
|
||||
Foo.a.b = 1;
|
||||
Foo.a.c = 2;
|
||||
Foo.a = { 'b': 1, 'c': 2 };
|
||||
|
||||
var matches = _.matches({ 'a': { 'b': 1 } });
|
||||
strictEqual(matches(Foo), true);
|
||||
@@ -9613,6 +9622,17 @@
|
||||
strictEqual(matches({ 'a': object2 }), false);
|
||||
});
|
||||
|
||||
test('should compare functions by reference', 3, function() {
|
||||
var object1 = { 'a': _.noop },
|
||||
object2 = { 'a': noop },
|
||||
object3 = { 'a': {} },
|
||||
matches = _.matchesProperty('a', object1);
|
||||
|
||||
strictEqual(matches({ 'a': object1 }), true);
|
||||
strictEqual(matches({ 'a': object2 }), false);
|
||||
strictEqual(matches({ 'a': object3 }), false);
|
||||
});
|
||||
|
||||
test('should not change match behavior if `value` is augmented', 9, function() {
|
||||
_.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) {
|
||||
var object = _.cloneDeep(source),
|
||||
@@ -9710,16 +9730,6 @@
|
||||
strictEqual(matches(object), true);
|
||||
});
|
||||
|
||||
test('should match properties when `value` is a function', 1, function() {
|
||||
function Foo() {}
|
||||
Foo.a = function() {};
|
||||
Foo.a.b = 1;
|
||||
Foo.a.c = 2;
|
||||
|
||||
var matches = _.matchesProperty('a', { 'b': 1 });
|
||||
strictEqual(matches(Foo), true);
|
||||
});
|
||||
|
||||
test('should match properties when `value` is not a plain object', 1, function() {
|
||||
function Foo(object) { _.assign(this, object); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user