mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add more underscore "functions" tests to test/test.js.
This commit is contained in:
85
test/test.js
85
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 '<p>' + func(text) + '</p>';
|
||||
});
|
||||
|
||||
equal(p('Fred, Wilma, & Pebbles'), '<p>Fred, Wilma, & Pebbles</p>');
|
||||
});
|
||||
|
||||
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 '<p>' + func(this.text) + '</p>';
|
||||
});
|
||||
|
||||
var object = { 'p': p, 'text': 'Fred, Wilma, & Pebbles' };
|
||||
equal(object.p(), '<p>Fred, Wilma, & Pebbles</p>');
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.zip');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user