From 600a4e86e1ed6389eb68b23e992e2afef16f4e61 Mon Sep 17 00:00:00 2001 From: jdalton Date: Mon, 23 Mar 2015 09:24:05 -0700 Subject: [PATCH] Ensure `_.matches` and `_.matchesProperty` work with function `value` params. --- lodash.src.js | 2 +- test/test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lodash.src.js b/lodash.src.js index 483e299f4..b89ca643a 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -2326,7 +2326,7 @@ } } var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)) && !isHostObject(object), - othIsObj = othTag == objectTag && !isHostObject(other), + othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)) && !isHostObject(other), isSameTag = objTag == othTag; if (isSameTag && !(objIsArr || objIsObj)) { diff --git a/test/test.js b/test/test.js index 5c2f08b24..81378a6a1 100644 --- a/test/test.js +++ b/test/test.js @@ -9494,6 +9494,16 @@ 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 = _.matches({ '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); } @@ -9672,6 +9682,16 @@ 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); }