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.
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { _, args, document, body } from './utils.js';
|
|
|
|
describe('slice and toArray', function() {
|
|
lodashStable.each(['slice', 'toArray'], function(methodName) {
|
|
var array = [1, 2, 3],
|
|
func = _[methodName];
|
|
|
|
it('`_.' + methodName + '` should return a dense array', function() {
|
|
var sparse = Array(3);
|
|
sparse[1] = 2;
|
|
|
|
var actual = func(sparse);
|
|
|
|
assert.ok('0' in actual);
|
|
assert.ok('2' in actual);
|
|
assert.deepStrictEqual(actual, sparse);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should treat array-like objects like arrays', function() {
|
|
var object = { '0': 'a', 'length': 1 };
|
|
assert.deepStrictEqual(func(object), ['a']);
|
|
assert.deepStrictEqual(func(args), array);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should return a shallow clone of arrays', function() {
|
|
var actual = func(array);
|
|
assert.deepStrictEqual(actual, array);
|
|
assert.notStrictEqual(actual, array);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should work with a node list for `collection`', function() {
|
|
if (document) {
|
|
try {
|
|
var actual = func(document.getElementsByTagName('body'));
|
|
} catch (e) {}
|
|
|
|
assert.deepStrictEqual(actual, [body]);
|
|
}
|
|
});
|
|
});
|
|
});
|