mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Add unit tests for _.where.
Former-commit-id: 5247bba20d7aa772867e29def99221faea376db1
This commit is contained in:
@@ -2198,7 +2198,7 @@
|
|||||||
'inLoop':
|
'inLoop':
|
||||||
'for (pass = true, propIndex = 0; propIndex < propsLength; propIndex++) {\n' +
|
'for (pass = true, propIndex = 0; propIndex < propsLength; propIndex++) {\n' +
|
||||||
' prop = props[propIndex];\n' +
|
' prop = props[propIndex];\n' +
|
||||||
' if (pass = value[prop] === properties[prop]) break\n' +
|
' if (!(pass = value[prop] === properties[prop])) break\n' +
|
||||||
'}\n' +
|
'}\n' +
|
||||||
'if (pass) result.push(value)'
|
'if (pass) result.push(value)'
|
||||||
});
|
});
|
||||||
|
|||||||
50
test/test.js
50
test/test.js
@@ -253,7 +253,9 @@
|
|||||||
|
|
||||||
test('should clone problem JScript properties (test in IE < 9)', function() {
|
test('should clone problem JScript properties (test in IE < 9)', function() {
|
||||||
deepEqual(_.clone(shadowed), shadowed);
|
deepEqual(_.clone(shadowed), shadowed);
|
||||||
|
ok(_.clone(shadowed) != shadowed);
|
||||||
deepEqual(_.clone(shadowed, true), shadowed);
|
deepEqual(_.clone(shadowed, true), shadowed);
|
||||||
|
ok(_.clone(shadowed, true) != shadowed);
|
||||||
});
|
});
|
||||||
}(1, 2, 3));
|
}(1, 2, 3));
|
||||||
|
|
||||||
@@ -1223,6 +1225,54 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('lodash.where');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var array = [
|
||||||
|
{ 'a': 1 },
|
||||||
|
{ 'a': 1 },
|
||||||
|
{ 'a': 1, 'b': 2 },
|
||||||
|
{ 'a': 2, 'b': 2 },
|
||||||
|
{ 'a': 3 }
|
||||||
|
];
|
||||||
|
|
||||||
|
test('should filter by properties', function() {
|
||||||
|
deepEqual(_.where(array, { 'a': 1 }), [{ 'a': 1 }, { 'a': 1 }, { 'a': 1, 'b': 2 }]);
|
||||||
|
deepEqual(_.where(array, { 'a': 2 }), [{ 'a': 2, 'b': 2 }]);
|
||||||
|
deepEqual(_.where(array, { 'a': 3 }), [{ 'a': 3 }]);
|
||||||
|
deepEqual(_.where(array, { 'b': 1 }), []);
|
||||||
|
deepEqual(_.where(array, { 'b': 2 }), [{ 'a': 1, 'b': 2 }, { 'a': 2, 'b': 2 }]);
|
||||||
|
deepEqual(_.where(array, { 'a': 1, 'b': 2 }), [{ 'a': 1, 'b': 2 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should filter by inherited properties', function() {
|
||||||
|
function Foo() {}
|
||||||
|
Foo.prototype = { 'b': 2 };
|
||||||
|
|
||||||
|
var properties = new Foo;
|
||||||
|
properties.a = 1;
|
||||||
|
|
||||||
|
deepEqual(_.where(array, properties), [{ 'a': 1, 'b': 2 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should filter by problem JScript properties (test in IE < 9)', function() {
|
||||||
|
var collection = [shadowed];
|
||||||
|
deepEqual(_.where(collection, shadowed), [shadowed]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should work with an object for `collection`', function() {
|
||||||
|
var collection = {
|
||||||
|
'x': { 'a': 1 },
|
||||||
|
'y': { 'a': 3 },
|
||||||
|
'z': { 'a': 1, 'b': 2 }
|
||||||
|
};
|
||||||
|
|
||||||
|
deepEqual(_.where(collection, { 'a': 1 }), [{ 'a': 1 }, { 'a': 1, 'b': 2 }]);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash.zipObject');
|
QUnit.module('lodash.zipObject');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user