mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Add unit tests to ensure non-underscore builds may include _.chain and _.findWhere methods.
Former-commit-id: 91a4ea5114a45bc5038a37d7ff4ea4b6212182ca
This commit is contained in:
@@ -90,10 +90,13 @@
|
||||
};
|
||||
|
||||
/** List of all Lo-Dash methods */
|
||||
var allMethods = _.functions(_).filter(function(methodName) {
|
||||
var lodashMethods = _.functions(_).filter(function(methodName) {
|
||||
return !/^_/.test(methodName);
|
||||
});
|
||||
|
||||
/** List of all methods */
|
||||
var allMethods = lodashMethods.concat('chain', 'findWhere');
|
||||
|
||||
/** List of "Arrays" category methods */
|
||||
var arraysMethods = [
|
||||
'compact',
|
||||
@@ -125,6 +128,7 @@
|
||||
|
||||
/** List of "Chaining" category methods */
|
||||
var chainingMethods = [
|
||||
'chain',
|
||||
'tap',
|
||||
'value'
|
||||
];
|
||||
@@ -315,10 +319,8 @@
|
||||
'unzip'
|
||||
];
|
||||
|
||||
/** List of methods used by Underscore */
|
||||
var underscoreMethods = _.without
|
||||
.apply(_, [allMethods].concat(lodashOnlyMethods))
|
||||
.concat('chain', 'findWhere');
|
||||
/** List of Underscore methods */
|
||||
var underscoreMethods = _.without.apply(_, [allMethods].concat(lodashOnlyMethods));
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
@@ -804,14 +806,15 @@
|
||||
(function() {
|
||||
var commands = [
|
||||
'backbone',
|
||||
'underscore'
|
||||
'underscore',
|
||||
'modern plus=chain'
|
||||
];
|
||||
|
||||
commands.forEach(function(command) {
|
||||
asyncTest('`lodash ' + command +'`', function() {
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
|
||||
build(['-s', command], function(data) {
|
||||
build(['-s'].concat(command.split(' ')), function(data) {
|
||||
var basename = path.basename(data.outputPath, '.js'),
|
||||
context = createContext();
|
||||
|
||||
@@ -843,6 +846,37 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('modifiers with findWhere');
|
||||
|
||||
(function() {
|
||||
var commands = [
|
||||
'underscore include=findWhere',
|
||||
'modern include=findWhere',
|
||||
'plus=findWhere'
|
||||
];
|
||||
|
||||
commands.forEach(function(command) {
|
||||
asyncTest('`lodash ' + command + '`', function() {
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
|
||||
build(['-s'].concat(command.split(' ')), function(data) {
|
||||
var basename = path.basename(data.outputPath, '.js'),
|
||||
context = createContext();
|
||||
|
||||
vm.runInContext(data.source, context);
|
||||
var lodash = context._;
|
||||
|
||||
var collection = [{ 'a': 1 }, { 'a': 1 }];
|
||||
deepEqual(lodash.findWhere(collection, { 'a': 1 }), collection[0], '_.findWhere: ' + basename);
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('underscore modifier');
|
||||
|
||||
(function() {
|
||||
@@ -985,23 +1019,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest('`lodash underscore include=findWhere`', function() {
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
|
||||
build(['-s', 'underscore', 'include=findWhere'], function(data) {
|
||||
var basename = path.basename(data.outputPath, '.js'),
|
||||
context = createContext();
|
||||
|
||||
vm.runInContext(data.source, context);
|
||||
var lodash = context._;
|
||||
|
||||
var collection = [{ 'a': 1 }, { 'a': 1 }];
|
||||
deepEqual(lodash.findWhere(collection, { 'a': 1 }), collection[0], '_.findWhere: ' + basename);
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest('`lodash underscore include=partial`', function() {
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
|
||||
@@ -1412,7 +1429,7 @@
|
||||
methodNames = (methodNames || []).concat(command.match(/category=(\S*)/)[1].split(/, */).map(capitalize));
|
||||
}
|
||||
if (!methodNames) {
|
||||
methodNames = allMethods.slice();
|
||||
methodNames = lodashMethods.slice();
|
||||
}
|
||||
if (/plus/.test(command)) {
|
||||
methodNames = methodNames.concat(command.match(/plus=(\S*)/)[1].split(/, */));
|
||||
@@ -1429,16 +1446,13 @@
|
||||
var result = getMethodsByCategory(category);
|
||||
|
||||
// limit category methods to those available for specific builds
|
||||
if (isBackbone) {
|
||||
result = result.filter(function(methodName) {
|
||||
return _.contains(backboneDependencies, methodName);
|
||||
});
|
||||
}
|
||||
else if (isUnderscore) {
|
||||
result = result.filter(function(methodName) {
|
||||
return _.contains(underscoreMethods, methodName);
|
||||
});
|
||||
}
|
||||
result = result.filter(function(methodName) {
|
||||
return _.contains(
|
||||
isBackbone ? backboneDependencies :
|
||||
isUnderscore ? underscoreMethods :
|
||||
lodashMethods, methodName
|
||||
);
|
||||
});
|
||||
if (result.length) {
|
||||
methodNames = _.without(methodNames, category);
|
||||
push.apply(methodNames, result);
|
||||
|
||||
@@ -3205,7 +3205,7 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('"Arrays" methods');
|
||||
QUnit.module('"Arrays" category methods');
|
||||
|
||||
(function() {
|
||||
var args = arguments;
|
||||
|
||||
Reference in New Issue
Block a user