mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
wip: code formatting nits continued
This commit is contained in:
42
test/slice-and-toArray.spec.js
Normal file
42
test/slice-and-toArray.spec.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import lodashStable from 'lodash';
|
||||
import { _, args, document, body } from './utils';
|
||||
|
||||
describe('slice and toArray', () => {
|
||||
lodashStable.each(['slice', 'toArray'], (methodName) => {
|
||||
const array = [1, 2, 3];
|
||||
const func = _[methodName];
|
||||
|
||||
it(`\`_.${methodName}\` should return a dense array`, () => {
|
||||
const sparse = Array(3);
|
||||
sparse[1] = 2;
|
||||
|
||||
const actual = func(sparse);
|
||||
|
||||
expect('0' in actual);
|
||||
expect('2' in actual);
|
||||
expect(actual).toEqual(sparse);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should treat array-like objects like arrays`, () => {
|
||||
const object = { 0: 'a', length: 1 };
|
||||
expect(func(object)).toEqual(['a']);
|
||||
expect(func(args)).toEqual(array);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should return a shallow clone of arrays`, () => {
|
||||
const actual = func(array);
|
||||
expect(actual).toEqual(array);
|
||||
assert.notStrictEqual(actual, array);
|
||||
});
|
||||
|
||||
it(`\`_.${methodName}\` should work with a node list for \`collection\``, () => {
|
||||
if (document) {
|
||||
try {
|
||||
var actual = func(document.getElementsByTagName('body'));
|
||||
} catch (e) {}
|
||||
|
||||
expect(actual).toEqual([body]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user