diff --git a/lodash.js b/lodash.js index 23e8b5e3f6..ecc0968abe 100644 --- a/lodash.js +++ b/lodash.js @@ -2198,7 +2198,7 @@ 'inLoop': 'for (pass = true, propIndex = 0; propIndex < propsLength; propIndex++) {\n' + ' prop = props[propIndex];\n' + - ' if (pass = value[prop] === properties[prop]) break\n' + + ' if (!(pass = value[prop] === properties[prop])) break\n' + '}\n' + 'if (pass) result.push(value)' }); diff --git a/test/test.js b/test/test.js index 5e78a26554..5022a075c2 100644 --- a/test/test.js +++ b/test/test.js @@ -253,7 +253,9 @@ test('should clone problem JScript properties (test in IE < 9)', function() { deepEqual(_.clone(shadowed), shadowed); + ok(_.clone(shadowed) != shadowed); deepEqual(_.clone(shadowed, true), shadowed); + ok(_.clone(shadowed, true) != shadowed); }); }(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'); (function() {