Ensure _.matches is tested against sources with more than one property too.

This commit is contained in:
John-David Dalton
2014-04-13 00:36:31 -07:00
parent ce16c4d37f
commit e306959ebe

View File

@@ -5803,17 +5803,19 @@
QUnit.module('lodash.matches'); QUnit.module('lodash.matches');
(function() { (function() {
var object = { 'a': 1, 'b': 2 }; var object = { 'a': 1, 'b': 2, 'c': 3 },
sources = [{ 'a': 1 }, { 'a': 1, 'c': 3 }];
test('should create a function that performs a deep comparison between a given object and the `source` object', 3, function() {
var matches = _.matches({ 'a': 1 });
test('should create a function that performs a deep comparison between a given object and the `source` object', 6, function() {
_.each(sources, function(source, index) {
var matches = _.matches(source);
strictEqual(matches.length, 1); strictEqual(matches.length, 1);
strictEqual(matches(object), true); strictEqual(matches(object), true);
matches = _.matches({ 'b': 1 }); matches = _.matches(index ? { 'c': 3, 'd': 4 } : { 'b': 1 });
strictEqual(matches(object), false); strictEqual(matches(object), false);
}); });
});
test('should return `true` when comparing an empty `source`', 1, function() { test('should return `true` when comparing an empty `source`', 1, function() {
var expected = _.map(empties, _.constant(true)); var expected = _.map(empties, _.constant(true));
@@ -5826,9 +5828,11 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
test('should not error error for falsey `object` values', 1, function() { test('should not error error for falsey `object` values', 2, function() {
var expected = _.map(falsey, _.constant(true)), var expected = _.map(falsey, _.constant(true));
matches = _.matches({ 'a': 1 });
_.each(sources, function(source) {
var matches = _.matches(source);
var actual = _.map(falsey, function(value, index) { var actual = _.map(falsey, function(value, index) {
try { try {
@@ -5839,6 +5843,7 @@
deepEqual(actual, expected); deepEqual(actual, expected);
}); });
});
test('should return `true` when comparing an empty `source` to a falsey `object`', 1, function() { test('should return `true` when comparing an empty `source` to a falsey `object`', 1, function() {
var expected = _.map(falsey, _.constant(true)), var expected = _.map(falsey, _.constant(true)),