getEle

说明

获取指定单个DOM元素

源码

用法

getEle.test.ts
1
import { getEle } from "../../utility/dom/getEle";
2
3
describe('getEle', () => {
4
test('getEle should return `null` when no matched', () => {
5
document.body.innerHTML = `
6
<div id="app"></div>
7
`;
8
9
const origin = [
10
'p', '.text'
11
];
12
13
for (const v of origin) {
14
expect(getEle(v)).toBe(null);
15
}
16
});
17
18
test('getEle should return the `DOM object` which has been matched', () => {
19
document.body.innerHTML = `
20
<div id="#app"></div>
21
`;
22
23
const origin = ['#app'];
24
25
for (const v of origin) {
26
expect(getEle(v)).toBe(
27
document.getElementById('app')
28
)
29
}
30
});
31
});
Copied!
最近更新 1yr ago
复制链接