mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* 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.
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { arrayProto, LARGE_ARRAY_SIZE } from './utils.js';
|
|
import head from '../head.js';
|
|
import first from '../first.js';
|
|
|
|
describe('head', function() {
|
|
var array = [1, 2, 3, 4];
|
|
|
|
it('should return the first element', function() {
|
|
assert.strictEqual(head(array), 1);
|
|
});
|
|
|
|
it('should return `undefined` when querying empty arrays', function() {
|
|
arrayProto[0] = 1;
|
|
assert.strictEqual(head([]), undefined);
|
|
arrayProto.length = 0;
|
|
});
|
|
|
|
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, head);
|
|
|
|
assert.deepStrictEqual(actual, [1, 4, 7]);
|
|
});
|
|
|
|
it('should be aliased', function() {
|
|
assert.strictEqual(first, head);
|
|
});
|
|
|
|
it('should return an unwrapped value when implicitly chaining', function() {
|
|
var wrapped = _(array);
|
|
assert.strictEqual(wrapped.head(), 1);
|
|
assert.strictEqual(wrapped.first(), 1);
|
|
});
|
|
|
|
it('should return a wrapped value when explicitly chaining', function() {
|
|
var wrapped = _(array).chain();
|
|
assert.ok(wrapped.head() instanceof _);
|
|
assert.ok(wrapped.first() instanceof _);
|
|
});
|
|
|
|
it('should not execute immediately when explicitly chaining', function() {
|
|
var wrapped = _(array).chain();
|
|
assert.strictEqual(wrapped.head().__wrapped__, array);
|
|
assert.strictEqual(wrapped.first().__wrapped__, array);
|
|
});
|
|
|
|
it('should work in a lazy sequence', function() {
|
|
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
|
|
smallArray = array;
|
|
|
|
lodashStable.each(['head', 'first'], function(methodName) {
|
|
lodashStable.times(2, function(index) {
|
|
var array = index ? largeArray : smallArray,
|
|
actual = _(array).filter(isEven)[methodName]();
|
|
|
|
assert.strictEqual(actual, _[methodName](_.filter(array, isEven)));
|
|
});
|
|
});
|
|
});
|
|
});
|