mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
wip: migrate to bun
This commit is contained in:
51
test/toArray.spec.ts
Normal file
51
test/toArray.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import assert from 'node:assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { arrayProto, LARGE_ARRAY_SIZE } from './utils';
|
||||
import toArray from '../src/toArray';
|
||||
|
||||
describe('toArray', () => {
|
||||
it('should convert objects to arrays', () => {
|
||||
assert.deepStrictEqual(toArray({ a: 1, b: 2 }), [1, 2]);
|
||||
});
|
||||
|
||||
it('should convert iterables to arrays', () => {
|
||||
if (Symbol && Symbol.iterator) {
|
||||
const object = { '0': 'a', length: 1 };
|
||||
object[Symbol.iterator] = arrayProto[Symbol.iterator];
|
||||
|
||||
assert.deepStrictEqual(toArray(object), ['a']);
|
||||
}
|
||||
});
|
||||
|
||||
it('should convert maps to arrays', () => {
|
||||
if (Map) {
|
||||
const map = new Map();
|
||||
map.set('a', 1);
|
||||
map.set('b', 2);
|
||||
assert.deepStrictEqual(toArray(map), [
|
||||
['a', 1],
|
||||
['b', 2],
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it('should convert strings to arrays', () => {
|
||||
assert.deepStrictEqual(toArray(''), []);
|
||||
assert.deepStrictEqual(toArray('ab'), ['a', 'b']);
|
||||
assert.deepStrictEqual(toArray(Object('ab')), ['a', 'b']);
|
||||
});
|
||||
|
||||
it('should work in a lazy sequence', () => {
|
||||
const array = lodashStable.range(LARGE_ARRAY_SIZE + 1);
|
||||
|
||||
const object = lodashStable.zipObject(
|
||||
lodashStable.times(LARGE_ARRAY_SIZE, (index) => [`key${index}`, index]),
|
||||
);
|
||||
|
||||
let actual = _(array).slice(1).map(String).toArray().value();
|
||||
assert.deepEqual(actual, lodashStable.map(array.slice(1), String));
|
||||
|
||||
actual = _(object).toArray().slice(1).map(String).value();
|
||||
assert.deepEqual(actual, _.map(toArray(object).slice(1), String));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user