Skip to content

Commit c68ea32

Browse files
committed
【ut】fix ut
1 parent 9a408d5 commit c68ea32

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

test/mapboxgl/core/MapExtendSpec.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -369,60 +369,61 @@ describe('MapExtend mapboxgl', () => {
369369
on: function () {},
370370
off: function () {}
371371
};
372-
for (const key in options) {
373-
spyOn(options, key).and.callThrough();
374-
}
375372

376373
class L7LayerTest extends CustomOverlayLayer {
377374
constructor() {
378-
const optionsData = {
379-
id: 'l7_layer_1',
380-
sourceId: 'l7_layer_1',
381-
events: ['click'],
382-
query: true,
383-
interaction: true,
384-
...options
385-
};
386-
for (const key in optionsData) {
387-
this[key] = optionsData;
388-
}
375+
super({ sourceId: 'l7_layer_1', query: true, interaction: true, events: ['click'] });
376+
this.id = 'l7_layer_1';
377+
this.sourceId = 'l7_layer_1';
378+
}
379+
380+
getSource() {
381+
return {};
382+
}
383+
384+
getLayer() {
385+
return {}
389386
}
390387
}
388+
const l7_layer_1 = new L7LayerTest();
389+
for (const key in options) {
390+
spyOn(l7_layer_1, key).and.callThrough();
391+
}
391392
map.overlayLayersManager = {
392-
l7_layer_1: new L7LayerTest(),
393+
l7_layer_1,
393394
heatmap_1: { id: 'heatmap_1' }
394395
};
395396
expect(map.getSource('l7_layer_1')).not.toBeUndefined();
396397
expect(map.getSource('raster-tiles')).not.toBeUndefined();
397-
expect(options.getSource.calls.count()).toEqual(1);
398+
expect(l7_layer_1.getSource.calls.count()).toEqual(1);
398399
expect(map.isSourceLoaded('l7_layer_1')).toBeTruthy();
399400
expect(map.isSourceLoaded('raster-tiles')).toBeTruthy();
400401
expect(map.getLayer('l7_layer_1')).not.toBeUndefined();
401402
expect(map.getLayer('simple-tiles')).not.toBeUndefined();
402403
expect(map.getLayer('heatmap_1')).toEqual(map.overlayLayersManager['heatmap_1']);
403-
expect(options.getLayer.calls.count()).toEqual(1);
404+
expect(l7_layer_1.getLayer.calls.count()).toEqual(1);
404405
const layerToAdd = { type: 'custom', id: 'add1', onAdd() {}, onRemove() {}, render() {} };
405406
map.addLayer(layerToAdd);
406407
expect(map.addLayer.calls.count()).toEqual(1);
407408
map.queryRenderedFeatures([0, 0], { layers: ['l7_layer_1', 'simple-tiles'] });
408-
expect(options.queryRenderedFeatures.calls.count()).toEqual(1);
409+
expect(l7_layer_1.queryRenderedFeatures.calls.count()).toEqual(1);
409410
map.querySourceFeatures('l7_layer_1');
410411
map.querySourceFeatures('raster-tiles');
411-
expect(options.querySourceFeatures.calls.count()).toEqual(1);
412+
expect(l7_layer_1.querySourceFeatures.calls.count()).toEqual(1);
412413
const cb = () => {};
413414
map.on('click', 'l7_layer_1', cb);
414415
map.on('click',cb);
415-
expect(options.on.calls.count()).toEqual(1);
416+
expect(l7_layer_1.on.calls.count()).toEqual(1);
416417
map.once('click', 'l7_layer_1', cb);
417418
map.once('click', cb);
418-
expect(options.once.calls.count()).toEqual(1);
419+
expect(l7_layer_1.once.calls.count()).toEqual(1);
419420
map.off('click', 'l7_layer_1', cb);
420421
map.off('click', cb);
421-
expect(options.off.calls.count()).toEqual(1);
422+
expect(l7_layer_1.off.calls.count()).toEqual(1);
422423
map.removeSource('l7_layer_1');
423424
map.removeLayer('simple-tiles');
424425
map.removeSource('raster-tiles');
425-
expect(options.removeSource.calls.count()).toEqual(1);
426+
expect(l7_layer_1.removeSource.calls.count()).toEqual(1);
426427
map.remove();
427428
done();
428429
});

0 commit comments

Comments
 (0)