mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Add isPreBuild flag and cleanup tests.
This commit is contained in:
71
test/test.js
71
test/test.js
@@ -183,6 +183,9 @@
|
|||||||
return result;
|
return result;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
/** Detects if running the pre-build version of Lo-Dash */
|
||||||
|
var isPreBuild = /getHolders/.test(_.partial(_.noop));
|
||||||
|
|
||||||
/** Used to check problem JScript properties (a.k.a. the [[DontEnum]] bug) */
|
/** Used to check problem JScript properties (a.k.a. the [[DontEnum]] bug) */
|
||||||
var shadowedProps = [
|
var shadowedProps = [
|
||||||
'constructor',
|
'constructor',
|
||||||
@@ -748,7 +751,7 @@
|
|||||||
var values = _.reject(falsey.slice(1), function(value) { return value == null; }),
|
var values = _.reject(falsey.slice(1), function(value) { return value == null; }),
|
||||||
expected = _.map(values, function(value) { return [value]; });
|
expected = _.map(values, function(value) { return [value]; });
|
||||||
|
|
||||||
var actual = _.map(values, function(value, index) {
|
var actual = _.map(values, function(value) {
|
||||||
try {
|
try {
|
||||||
var bound = _.bind(fn, value);
|
var bound = _.bind(fn, value);
|
||||||
return bound();
|
return bound();
|
||||||
@@ -791,7 +794,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should support placeholders', 4, function() {
|
test('should support placeholders', 4, function() {
|
||||||
if (_._iteratorTemplate) {
|
if (isPreBuild) {
|
||||||
var object = {},
|
var object = {},
|
||||||
bound = _.bind(fn, object, _, 'b', _);
|
bound = _.bind(fn, object, _, 'b', _);
|
||||||
|
|
||||||
@@ -806,7 +809,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should create a function with a `length` of `0`', 2, function() {
|
test('should create a function with a `length` of `0`', 2, function() {
|
||||||
var func = function(a, b, c) {},
|
var fn = function(a, b, c) {},
|
||||||
bound = _.bind(fn, {});
|
bound = _.bind(fn, {});
|
||||||
|
|
||||||
strictEqual(bound.length, 0);
|
strictEqual(bound.length, 0);
|
||||||
@@ -979,13 +982,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var func = _.bindKey(object, 'greet', 'hi');
|
var bound = _.bindKey(object, 'greet', 'hi');
|
||||||
equal(func(), 'hi fred');
|
equal(bound(), 'hi fred');
|
||||||
|
|
||||||
object.greet = function(greeting) {
|
object.greet = function(greeting) {
|
||||||
return greeting + ' ' + this.name + '!';
|
return greeting + ' ' + this.name + '!';
|
||||||
};
|
};
|
||||||
equal(func(), 'hi fred!');
|
equal(bound(), 'hi fred!');
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -6300,9 +6303,7 @@
|
|||||||
isPartial = methodName == 'partial';
|
isPartial = methodName == 'partial';
|
||||||
|
|
||||||
test('`_.' + methodName + '` partially applies arguments', 1, function() {
|
test('`_.' + methodName + '` partially applies arguments', 1, function() {
|
||||||
var fn = function(a) { return a; },
|
var par = func(_.identity, 'a');
|
||||||
par = func(fn, 'a');
|
|
||||||
|
|
||||||
equal(par(), 'a');
|
equal(par(), 'a');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -6322,12 +6323,31 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', 1, function() {
|
test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked with additional arguments', 1, function() {
|
||||||
var fn = function(a) { return a; },
|
var par = func(_.identity);
|
||||||
par = func(fn);
|
|
||||||
|
|
||||||
equal(par('a'), 'a');
|
equal(par('a'), 'a');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('`_.' + methodName + '` should support placeholders', 4, function() {
|
||||||
|
if (isPreBuild) {
|
||||||
|
var fn = function() { return slice.call(arguments); },
|
||||||
|
par = func(fn, _, 'b', _);
|
||||||
|
|
||||||
|
deepEqual(par('a', 'c'), ['a', 'b', 'c']);
|
||||||
|
deepEqual(par('a'), ['a', 'b', undefined]);
|
||||||
|
deepEqual(par(), [undefined, 'b', undefined]);
|
||||||
|
|
||||||
|
if (isPartial) {
|
||||||
|
deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
|
||||||
|
} else {
|
||||||
|
par = func(fn, _, 'c', _);
|
||||||
|
deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(4);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should not alter the `this` binding', 3, function() {
|
test('`_.' + methodName + '` should not alter the `this` binding', 3, function() {
|
||||||
var fn = function() { return this.a; },
|
var fn = function() { return this.a; },
|
||||||
object = { 'a': 1 };
|
object = { 'a': 1 };
|
||||||
@@ -6353,36 +6373,13 @@
|
|||||||
function Foo(value) {
|
function Foo(value) {
|
||||||
return value && object;
|
return value && object;
|
||||||
}
|
}
|
||||||
var par = func(Foo),
|
var object = {},
|
||||||
object = {};
|
par = func(Foo);
|
||||||
|
|
||||||
ok(new par instanceof Foo);
|
ok(new par instanceof Foo);
|
||||||
strictEqual(new par(true), object);
|
strictEqual(new par(true), object);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should support placeholders', 4, function() {
|
|
||||||
if (_._iteratorTemplate) {
|
|
||||||
var fn = function() {
|
|
||||||
return slice.call(arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
var par = func(fn, _, 'b', _);
|
|
||||||
deepEqual(par('a', 'c'), ['a', 'b', 'c']);
|
|
||||||
deepEqual(par('a'), ['a', 'b', undefined]);
|
|
||||||
deepEqual(par(), [undefined, 'b', undefined]);
|
|
||||||
|
|
||||||
if (isPartial) {
|
|
||||||
deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
|
|
||||||
} else {
|
|
||||||
par = func(fn, _, 'c', _);
|
|
||||||
deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(4);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('`_.' + methodName + '` should clone metadata for created functions', 3, function() {
|
test('`_.' + methodName + '` should clone metadata for created functions', 3, function() {
|
||||||
var greet = function(greeting, name) {
|
var greet = function(greeting, name) {
|
||||||
return greeting + ' ' + name;
|
return greeting + ' ' + name;
|
||||||
|
|||||||
Reference in New Issue
Block a user