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.
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { LARGE_ARRAY_SIZE, _, falsey } from './utils.js';
|
|
import compact from '../compact.js';
|
|
import slice from '../slice.js';
|
|
|
|
describe('compact', function() {
|
|
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE).concat(null);
|
|
|
|
it('should filter falsey values', function() {
|
|
var array = ['0', '1', '2'];
|
|
assert.deepStrictEqual(compact(falsey.concat(array)), array);
|
|
});
|
|
|
|
it('should work when in-between lazy operators', function() {
|
|
var actual = _(falsey).thru(slice).compact().thru(slice).value();
|
|
assert.deepEqual(actual, []);
|
|
|
|
actual = _(falsey).thru(slice).push(true, 1).compact().push('a').value();
|
|
assert.deepEqual(actual, [true, 1, 'a']);
|
|
});
|
|
|
|
it('should work in a lazy sequence', function() {
|
|
var actual = _(largeArray).slice(1).compact().reverse().take().value();
|
|
assert.deepEqual(actual, _.take(compact(slice(largeArray, 1)).reverse()));
|
|
});
|
|
|
|
it('should work in a lazy sequence with a custom `_.iteratee`', function() {
|
|
var iteratee = _.iteratee,
|
|
pass = false;
|
|
|
|
_.iteratee = identity;
|
|
|
|
try {
|
|
var actual = _(largeArray).slice(1).compact().value();
|
|
pass = lodashStable.isEqual(actual, compact(slice(largeArray, 1)));
|
|
} catch (e) {console.log(e);}
|
|
|
|
assert.ok(pass);
|
|
_.iteratee = iteratee;
|
|
});
|
|
});
|