mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +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
51
test/last.js
Normal file
51
test/last.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { LARGE_ARRAY_SIZE } from './utils.js';
|
||||
import last from '../last.js';
|
||||
|
||||
describe('last', function() {
|
||||
var array = [1, 2, 3, 4];
|
||||
|
||||
it('should return the last element', function() {
|
||||
assert.strictEqual(last(array), 4);
|
||||
});
|
||||
|
||||
it('should return `undefined` when querying empty arrays', function() {
|
||||
var array = [];
|
||||
array['-1'] = 1;
|
||||
|
||||
assert.strictEqual(last([]), undefined);
|
||||
});
|
||||
|
||||
it('should work as an iteratee for methods like `_.map`', function() {
|
||||
var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
|
||||
actual = lodashStable.map(array, last);
|
||||
|
||||
assert.deepStrictEqual(actual, [3, 6, 9]);
|
||||
});
|
||||
|
||||
it('should return an unwrapped value when implicitly chaining', function() {
|
||||
assert.strictEqual(_(array).last(), 4);
|
||||
});
|
||||
|
||||
it('should return a wrapped value when explicitly chaining', function() {
|
||||
assert.ok(_(array).chain().last() instanceof _);
|
||||
});
|
||||
|
||||
it('should not execute immediately when explicitly chaining', function() {
|
||||
var wrapped = _(array).chain().last();
|
||||
assert.strictEqual(wrapped.__wrapped__, array);
|
||||
});
|
||||
|
||||
it('should work in a lazy sequence', function() {
|
||||
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
|
||||
smallArray = array;
|
||||
|
||||
lodashStable.times(2, function(index) {
|
||||
var array = index ? largeArray : smallArray,
|
||||
wrapped = _(array).filter(isEven);
|
||||
|
||||
assert.strictEqual(wrapped.last(), last(_.filter(array, isEven)));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user