Skip to content

Commit 4ce0867

Browse files
committed
【fix】UT
1 parent bae7565 commit 4ce0867

3 files changed

Lines changed: 34 additions & 16 deletions

File tree

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ import mbglmap, { CRS, proj4, revertCRS } from '../../tool/mock_mapboxgl_map';
1414
import '../../resources/WebMapV3.js';
1515
import '../../resources/WebMapV5.js';
1616
var server = 'http://localhost:8190/iportal/';
17-
if (!Array.prototype.at) {
18-
Array.prototype.at = function(n) {
19-
n = Math.trunc(n) || 0;
20-
if (n < 0) n += this.length;
21-
if (n < 0 || n >= this.length) return undefined;
22-
return this[n];
23-
};
24-
}
2517
describe('mapboxgl-webmap3.0', () => {
2618
var originalTimeout, testDiv;
2719
var id = 617580084;

test/maplibregl/mapping/WebMapV3Spec.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import * as mockL7 from '../../tool/mock_l7';
1313
import mbglmap, { CRS, proj4 } from '../../tool/mock_maplibregl_map';
1414
import '../../resources/WebMapV3.js';
1515
import '../../resources/WebMapV5.js';
16-
if (!Array.prototype.at) {
17-
Array.prototype.at = function(n) {
18-
n = Math.trunc(n) || 0;
19-
if (n < 0) n += this.length;
20-
if (n < 0 || n >= this.length) return undefined;
21-
return this[n];
22-
};
23-
}
16+
2417
describe('maplibregl-webmap3.0', () => {
2518
var originalTimeout, testDiv;
2619
var server = 'http://localhost:8190/iportal/';

test/tool/mock_l7.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
if (!Array.prototype.at) {
2+
Object.defineProperty(Array.prototype, 'at', {
3+
value: function at(index) {
4+
// 1. 让 O 成为 ToObject(this)
5+
if (this == null) {
6+
throw new TypeError('Cannot convert undefined or null to object');
7+
}
8+
var O = Object(this);
9+
10+
// 2. 让 len 成为 ToLength(O.length)
11+
var len = O.length >>> 0;
12+
13+
// 3. 让 relativeIndex 成为 ToInteger(index)
14+
var relativeIndex = Math.trunc(index) || 0;
15+
16+
// 如果参数是 NaN,Math.trunc(NaN) 是 NaN,NaN || 0 会将其变成 0
17+
// 这符合标准(规范中 ToIntegerOrInfinity(undefined) 结果为 0)
18+
19+
// 4. 计算实际索引
20+
var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
21+
22+
// 5. 边界检查:如果超出范围,返回 undefined
23+
if (k < 0 || k >= len) {
24+
return undefined;
25+
}
26+
27+
// 6. 返回对应的属性值
28+
return O[k];
29+
},
30+
writable: true,
31+
configurable: true
32+
});
33+
}
134
class Event {
235
constructor() {
336
this.stacks = {};

0 commit comments

Comments
 (0)