Skip to content

Commit 77e9293

Browse files
committed
【fix】UT
1 parent 01960a1 commit 77e9293

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

test/common/mapping/WebMapV2BaseSpec.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createWebMapV2BaseExtending } from '../../../src/common/mapping/WebMapV
22
import { FetchRequest } from '../../../src/common/util/FetchRequest';
33
import * as epsgDefine from '../../../src/common/mapping/utils/epsg-define';
44
import cloneDeep from 'lodash.clonedeep';
5+
import { Canvg } from 'canvg';
56

67
describe('WebMapBaseSpec.js', () => {
78
const id = 123;
@@ -1018,17 +1019,13 @@ describe('WebMapBaseSpec.js', () => {
10181019
start: jasmine.createSpy('start'),
10191020
stop: jasmine.createSpy('stop')
10201021
};
1021-
window.canvg = {
1022-
default: {
1023-
from: (ctx) => {
1024-
return {
1025-
then: (resolveCb) => {
1026-
resolveCb(mockRes);
1027-
}
1028-
};
1022+
spyOn( Canvg , 'from').and.callFake( (ctx) => {
1023+
return {
1024+
then: (resolveCb) => {
1025+
resolveCb(mockRes);
10291026
}
1030-
}
1031-
};
1027+
};
1028+
})
10321029
const svgUrl = 'http://testsvg';
10331030
const divDom = {
10341031
appendChild: jasmine.createSpy('appendChild')
@@ -1039,7 +1036,6 @@ describe('WebMapBaseSpec.js', () => {
10391036
expect(divDom.appendChild).toHaveBeenCalled();
10401037
expect(callBack).toHaveBeenCalled();
10411038
expect(webMapBase.canvgsV.length).toBe(1);
1042-
window.canvg = undefined;
10431039
done();
10441040
});
10451041

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ArrayStatistic } from '@supermapgis/iclient-common/util/ArrayStatistic'
66
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
77
import * as DataFlowServiceUtil from '../../../src/mapboxgl/services/DataFlowService';
88
import '../../resources/WebMapV5.js';
9+
import { Canvg } from 'canvg';
910

1011
function DataFlowService(serviceUrl) {
1112
const dataflowFeature = {
@@ -311,12 +312,9 @@ describe('mapboxgl_WebMapV2', () => {
311312
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
312313
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
313314
window.jsonsql = { query: () => [{}] };
314-
window.canvg = {
315-
default: {
316-
from: (ctx, url, callback) =>
317-
Promise.resolve({ stop: jasmine.createSpy('stop'), start: jasmine.createSpy('start') })
318-
}
319-
};
315+
spyOn(Canvg, 'from').and.callFake((ctx, url, callback) =>
316+
Promise.resolve({ stop: jasmine.createSpy('stop'), start: jasmine.createSpy('start') })
317+
);
320318
window.geostats = class {
321319
setSerie() {}
322320
};
@@ -346,7 +344,6 @@ describe('mapboxgl_WebMapV2', () => {
346344
mapboxgl.CRS = undefined;
347345
mapboxgl.proj4 = undefined;
348346
window.jsonsql = undefined;
349-
window.canvg = undefined;
350347
window.geostats = undefined;
351348
window.EchartsLayer = undefined;
352349
dataFlowServiceSpyTest = null;

test/maplibregl/mapping/WebMapV2Spec.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ArrayStatistic } from '@supermapgis/iclient-common/util/ArrayStatistic'
66
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
77
import * as DataFlowServiceUtil from '../../../src/maplibregl/services/DataFlowService';
88
import '../../resources/WebMapV5.js';
9+
import { Canvg } from 'canvg';
910

1011
function DataFlowService(serviceUrl) {
1112
const dataflowFeature = {
@@ -312,12 +313,9 @@ describe('maplibregl_WebMapV2', () => {
312313
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
313314

314315
window.jsonsql = { query: () => [{}] };
315-
window.canvg = {
316-
default: {
317-
from: (ctx, url, callback) =>
318-
Promise.resolve({ stop: jasmine.createSpy('stop'), start: jasmine.createSpy('start') })
319-
}
320-
};
316+
spyOn( Canvg , 'from').and.callFake((ctx, url, callback) =>{
317+
return Promise.resolve({ stop: jasmine.createSpy('stop'), start: jasmine.createSpy('start') })
318+
})
321319
window.geostats = class {
322320
setSerie() {}
323321
};
@@ -347,7 +345,6 @@ describe('maplibregl_WebMapV2', () => {
347345
maplibregl.CRS = undefined;
348346
maplibregl.proj4 = undefined;
349347
window.jsonsql = undefined;
350-
window.canvg = undefined;
351348
window.geostats = undefined;
352349
window.EchartsLayer = undefined;
353350
});

0 commit comments

Comments
 (0)