From 4f0a5e937bea4a3b1fc010b3648d2e8ce2dfd63b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 11 Oct 2015 21:22:50 -0700 Subject: [PATCH] Add `_.juxt` tests. --- test/test.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 206f6c665..26c185066 100644 --- a/test/test.js +++ b/test/test.js @@ -2527,7 +2527,7 @@ QUnit.module('lodash.conj'); (function() { - QUnit.test('should return `true` if all predicates return truthy', function(assert) { + QUnit.test('should create a function that returns `true` if all predicates return truthy', function(assert) { assert.expect(1); var conjed = _.conj(_.constant(true), _.constant(1), _.constant('a')); @@ -3802,7 +3802,7 @@ QUnit.module('lodash.disj'); (function() { - QUnit.test('should return `true` if any predicates return truthy', function(assert) { + QUnit.test('should create a function that returns `true` if any predicates return truthy', function(assert) { assert.expect(2); var disjed = _.disj(_.constant(false), _.constant(1), _.constant('')); @@ -11077,6 +11077,63 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.juxt'); + + (function() { + QUnit.test('should create a function that invokes `iteratees`', function(assert) { + assert.expect(1); + + var juxted = _.juxt(Math.max, Math.min); + assert.deepEqual(juxted(1, 2, 3, 4), [4, 1]); + }); + + QUnit.test('should use `_.identity` when a predicate is nullish', function(assert) { + assert.expect(1); + + var juxted = _.juxt(undefined, null); + assert.deepEqual(juxted('a', 'b', 'c'), ['a', 'a']); + }); + + QUnit.test('should work with a "_.property" style predicate', function(assert) { + assert.expect(1); + + var object = { 'a': 1, 'b': 2 }, + juxted = _.juxt('b', 'a'); + + assert.deepEqual(juxted(object), [2, 1]); + }); + + QUnit.test('should work with a "_.matches" style predicate', function(assert) { + assert.expect(1); + + var object = { 'a': 1, 'b': 2 }, + juxted = _.juxt({ 'c': 3 }, { 'a': 1 }); + + assert.deepEqual(juxted(object), [false, true]); + }); + + QUnit.test('should provide multiple arguments to predicates', function(assert) { + assert.expect(1); + + var juxted = _.juxt(function() { + return slice.call(arguments); + }); + + assert.deepEqual(juxted('a', 'b', 'c'), [['a', 'b', 'c']]); + }); + + QUnit.test('should not set a `this` binding', function(assert) { + assert.expect(1); + + var juxted = _.juxt(function() { return this.b; }, function() { return this.a; }), + object = { 'juxted': juxted, 'a': 1, 'b': 2 }; + + assert.deepEqual(object.juxted(), [2, 1]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.map'); (function() {