mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +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
56
test/reduceRight.js
Normal file
56
test/reduceRight.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { slice } from './utils.js';
|
||||
import reduceRight from '../reduceRight.js';
|
||||
|
||||
describe('reduceRight', function() {
|
||||
var array = [1, 2, 3];
|
||||
|
||||
it('should use the last element of a collection as the default `accumulator`', function() {
|
||||
assert.strictEqual(reduceRight(array), 3);
|
||||
});
|
||||
|
||||
it('should provide correct `iteratee` arguments when iterating an array', function() {
|
||||
var args;
|
||||
|
||||
reduceRight(array, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
}, 0);
|
||||
|
||||
assert.deepStrictEqual(args, [0, 3, 2, array]);
|
||||
|
||||
args = undefined;
|
||||
reduceRight(array, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(args, [3, 2, 1, array]);
|
||||
});
|
||||
|
||||
it('should provide correct `iteratee` arguments when iterating an object', function() {
|
||||
var args,
|
||||
object = { 'a': 1, 'b': 2 },
|
||||
isFIFO = lodashStable.keys(object)[0] == 'a';
|
||||
|
||||
var expected = isFIFO
|
||||
? [0, 2, 'b', object]
|
||||
: [0, 1, 'a', object];
|
||||
|
||||
reduceRight(object, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
}, 0);
|
||||
|
||||
assert.deepStrictEqual(args, expected);
|
||||
|
||||
args = undefined;
|
||||
expected = isFIFO
|
||||
? [2, 1, 'a', object]
|
||||
: [1, 2, 'b', object];
|
||||
|
||||
reduceRight(object, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(args, expected);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user