toStrictArray

说明

将给定的类数组转化为严格的数组(非原地)

源码

用法

toStrictArray.test.ts
1
import { toStrictArray } from "../../utility/array/toStrictArray";
2
3
describe('toStrictArray', () => {
4
test('toStrictArray should receive an `ArrayLike` and return the `Array`', () => {
5
document.body.innerHTML += `
6
<div></div>
7
<div></div>
8
`;
9
const received1 = { length: 0 };
10
const received2 = {
11
0: 'ddzy',
12
1: 20,
13
length: 2,
14
};
15
const received3 = document.querySelectorAll('div');
16
const received4 = [1, 2, 3, 4];
17
18
const result1 = toStrictArray(received1);
19
const result2 = toStrictArray(received2);
20
const result3 = toStrictArray(received3);
21
const result4 = toStrictArray(received4);
22
23
expect(result1.length).toBe(0);
24
expect(result2.length).toBe(2);
25
expect(result3.length).toBe(2);
26
expect(result4.length).toBe(4);
27
28
expect(result2[0]).toBe(received2[0]);
29
expect(result3[0]).toBe(received3[0]);
30
expect(result4[0]).toBe(received4[0]);
31
});
32
});
Copied!
最近更新 1yr ago
复制链接