Add _.matches and _.matchesProperty tests for inherited properties.

This commit is contained in:
jdalton
2015-03-22 00:45:36 -07:00
parent f20d8f5cc0
commit d7a99c6618

View File

@@ -9484,6 +9484,25 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should match inherited `value` properties', 1, function() {
function Foo() { this.a = 1; }
Foo.prototype.b = 2;
var object = { 'a': new Foo },
matches = _.matches({ 'a': { 'b': 2 } });
strictEqual(matches(object), true);
});
test('should match properties when `value` is not a plain object', 1, function() {
function Foo(object) { _.assign(this, object); }
var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
matches = _.matches({ 'a': { 'b': 1 } });
strictEqual(matches(object), true);
});
test('should not match by inherited `source` properties', 1, function() { test('should not match by inherited `source` properties', 1, function() {
function Foo() { this.a = 1; } function Foo() { this.a = 1; }
Foo.prototype.b = 2; Foo.prototype.b = 2;
@@ -9643,7 +9662,26 @@
deepEqual(actual, [false, false, true]); deepEqual(actual, [false, false, true]);
}); });
test('should not match by inherited `value` properties', 1, function() { test('should match inherited `value` properties', 1, function() {
function Foo() { this.a = 1; }
Foo.prototype.b = 2;
var object = { 'a': new Foo },
matches = _.matchesProperty('a', { 'b': 2 });
strictEqual(matches(object), true);
});
test('should match properties when `value` is not a plain object', 1, function() {
function Foo(object) { _.assign(this, object); }
var object = new Foo({ 'a': new Foo({ 'b': 1, 'c': 2 }) }),
matches = _.matchesProperty('a', { 'b': 1 });
strictEqual(matches(object), true);
});
test('should not match inherited `source` properties', 1, function() {
function Foo() { this.a = 1; } function Foo() { this.a = 1; }
Foo.prototype.b = 2; Foo.prototype.b = 2;