Files
lodash/test/slice-and-toArray.js
Benjamin Tan d5ef31929a 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.
2019-02-12 09:11:32 -08:00

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]);
}
});
});
});