mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-15 05:07:49 +00:00
Ensure _.matches is tested against sources with more than one property too.
This commit is contained in:
21
test/test.js
21
test/test.js
@@ -5803,17 +5803,19 @@
|
||||
QUnit.module('lodash.matches');
|
||||
|
||||
(function() {
|
||||
var object = { 'a': 1, 'b': 2 };
|
||||
|
||||
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 });
|
||||
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', 6, function() {
|
||||
_.each(sources, function(source, index) {
|
||||
var matches = _.matches(source);
|
||||
strictEqual(matches.length, 1);
|
||||
strictEqual(matches(object), true);
|
||||
|
||||
matches = _.matches({ 'b': 1 });
|
||||
matches = _.matches(index ? { 'c': 3, 'd': 4 } : { 'b': 1 });
|
||||
strictEqual(matches(object), false);
|
||||
});
|
||||
});
|
||||
|
||||
test('should return `true` when comparing an empty `source`', 1, function() {
|
||||
var expected = _.map(empties, _.constant(true));
|
||||
@@ -5826,9 +5828,11 @@
|
||||
deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('should not error error for falsey `object` values', 1, function() {
|
||||
var expected = _.map(falsey, _.constant(true)),
|
||||
matches = _.matches({ 'a': 1 });
|
||||
test('should not error error for falsey `object` values', 2, function() {
|
||||
var expected = _.map(falsey, _.constant(true));
|
||||
|
||||
_.each(sources, function(source) {
|
||||
var matches = _.matches(source);
|
||||
|
||||
var actual = _.map(falsey, function(value, index) {
|
||||
try {
|
||||
@@ -5839,6 +5843,7 @@
|
||||
|
||||
deepEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
|
||||
test('should return `true` when comparing an empty `source` to a falsey `object`', 1, function() {
|
||||
var expected = _.map(falsey, _.constant(true)),
|
||||
|
||||
Reference in New Issue
Block a user