From f9c34d680893f8ba8091b20b1a4738327f6249ac Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 20 Oct 2013 23:35:42 -0700 Subject: [PATCH] Add more underscore "functions" tests to test/test.js. --- test/test.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/test/test.js b/test/test.js index 312faa780..1f10f1922 100644 --- a/test/test.js +++ b/test/test.js @@ -329,6 +329,25 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.after'); + + (function() { + test('should create a function that executes `func` after `n` calls', 4, function() { + function after(n, times) { + var count = 0; + _.times(times, _.after(n, function() { count++; })); + return count; + } + + strictEqual(after(5, 5), 1, 'after(n) should execute `func` after being called `n` times'); + strictEqual(after(5, 4), 0, 'after(n) should not execute `func` unless called `n` times'); + strictEqual(after(0, 0), 0, 'after(0) should not execute `func` immediately'); + strictEqual(after(0, 1), 1, 'after(0) should execute `func` when called once'); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.assign'); (function() { @@ -754,6 +773,30 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.compose'); + + (function() { + test('should create a function that is the composition of the provided functions', 1, function() { + var realNameMap = { + 'pebbles': 'penelope' + }; + + var format = function(name) { + name = realNameMap[name.toLowerCase()] || name; + return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); + }; + + var greet = function(formatted) { + return 'Hiya ' + formatted + '!'; + }; + + var welcome = _.compose(greet, format); + equal(welcome('pebbles'), 'Hiya Penelope!'); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.contains'); (function() { @@ -2798,7 +2841,7 @@ deepEqual(args, ['a', 'b']); }); - test('should correct set the `this` binding', 1, function() { + test('should correctly set the `this` binding', 1, function() { var actual = _.isEqual('a', 'b', function(a, b) { return this[a] == this[b]; }, { 'a': 1, 'b': 1 }); @@ -3706,7 +3749,7 @@ deepEqual(args, expected); }); - test('should correct set the `this` binding', 1, function() { + test('should correctly set the `this` binding', 1, function() { var actual = _.omit(object, function(num) { return num === this.a; }, { 'a': 1 }); @@ -3942,7 +3985,7 @@ deepEqual(args, expected); }); - test('should correct set the `this` binding', 1, function() { + test('should correctly set the `this` binding', 1, function() { var actual = _.pick(object, function(num) { return num === this.b; }, { 'b': 2 }); @@ -5003,7 +5046,7 @@ equal(compiled({ 'a': 'A' }), 'ABC'); }); - test('should work correct with `this` references', 2, function() { + test('should work correctly with `this` references', 2, function() { var compiled = _.template('a<%= this.b %>c'); root.b = 'b'; @@ -5935,6 +5978,40 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.wrap'); + + (function() { + test('should create a wrapped function', 1, function() { + var p = _.wrap(_.escape, function(func, text) { + return '

' + func(text) + '

'; + }); + + equal(p('Fred, Wilma, & Pebbles'), '

Fred, Wilma, & Pebbles

'); + }); + + test('should pass the correct `wrapper` arguments', 1, function() { + var args; + + var wrapped = _.wrap(_.noop, function() { + args || (args = slice.call(arguments)); + }); + + wrapped(1, 2, 3); + deepEqual(args, [_.noop, 1, 2, 3]); + }); + + test('should not set a `this` binding', 1, function() { + var p = _.wrap(_.escape, function(func) { + return '

' + func(this.text) + '

'; + }); + + var object = { 'p': p, 'text': 'Fred, Wilma, & Pebbles' }; + equal(object.p(), '

Fred, Wilma, & Pebbles

'); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.zip'); (function() {