mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Add initial test files from lodash v4. (#4172)
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
52
test/curry-methods.js
Normal file
52
test/curry-methods.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { _, slice } from './utils.js';
|
||||
import curry from '../curry.js';
|
||||
|
||||
describe('curry methods', function() {
|
||||
lodashStable.each(['curry', 'curryRight'], function(methodName) {
|
||||
var func = _[methodName],
|
||||
fn = function(a, b) { return slice.call(arguments); },
|
||||
isCurry = methodName == 'curry';
|
||||
|
||||
it('`_.' + methodName + '` should not error on functions with the same name as lodash methods', function() {
|
||||
function run(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
var curried = func(run);
|
||||
|
||||
try {
|
||||
var actual = curried(1)(2);
|
||||
} catch (e) {}
|
||||
|
||||
assert.strictEqual(actual, 3);
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should work for function names that shadow those on `Object.prototype`', function() {
|
||||
var curried = curry(function hasOwnProperty(a, b, c) {
|
||||
return [a, b, c];
|
||||
});
|
||||
|
||||
var expected = [1, 2, 3];
|
||||
|
||||
assert.deepStrictEqual(curried(1)(2)(3), expected);
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', function() {
|
||||
var array = [fn, fn, fn],
|
||||
object = { 'a': fn, 'b': fn, 'c': fn };
|
||||
|
||||
lodashStable.each([array, object], function(collection) {
|
||||
var curries = lodashStable.map(collection, func),
|
||||
expected = lodashStable.map(collection, lodashStable.constant(isCurry ? ['a', 'b'] : ['b', 'a']));
|
||||
|
||||
var actual = lodashStable.map(curries, function(curried) {
|
||||
return curried('a')('b');
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user