Skip to content

Commit c05b3eb

Browse files
committed
【fix】优化不稳定UT
1 parent 35d8961 commit c05b3eb

File tree

4 files changed

+72
-79
lines changed

4 files changed

+72
-79
lines changed

test/leaflet/components/search/SearchViewSpec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ describe('leaflet_search_SearchView', () => {
184184
return Promise.resolve();
185185
});
186186
spyOn(poiSearch.viewModel.map, 'setView').and.callThrough();
187-
document.getElementsByClassName('component-search__settings__name')[0].click()
188-
document.getElementsByClassName('component-citytabpag__content')[0].childNodes[0].click();
189-
setTimeout(() => {
187+
poiSearch.viewModel.map.on('zoomend',()=>{
190188
try {
191189
expect(poiSearch.viewModel.map.setView).toHaveBeenCalled();
192190
done();
@@ -195,7 +193,9 @@ describe('leaflet_search_SearchView', () => {
195193
expect(false).toBeTruthy();
196194
done();
197195
}
198-
}, 0);
196+
})
197+
document.getElementsByClassName('component-search__settings__name')[0].click()
198+
document.getElementsByClassName('component-citytabpag__content')[0].childNodes[0].click();
199199

200200
})
201201
})

test/openlayers/services/AddressMatchServiceSpec.js

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ describe('openlayers_AddressMatchService', () => {
3333
var codingFailedEventArgs = null, codingSuccessEventArgs = null;
3434
var codeCompleted = (analyseEventArgs) => {
3535
codingSuccessEventArgs = analyseEventArgs;
36+
try {
37+
expect(addressCodeService).not.toBeNull();
38+
expect(codingSuccessEventArgs).not.toBeNull();
39+
expect(codingSuccessEventArgs.type).toBe('processCompleted');
40+
expect(codingSuccessEventArgs.result).not.toBeNull();
41+
expect(codingSuccessEventArgs.result.length).toBe(10);
42+
GeoCodingParams.destroy();
43+
codingSuccessEventArgs = null;
44+
codingFailedEventArgs = null;
45+
done();
46+
} catch (exception) {
47+
console.log("'code'案例失败:" + exception.name + ":" + exception.message);
48+
GeoCodingParams.destroy();
49+
codingFailedEventArgs = null;
50+
codingSuccessEventArgs = null;
51+
expect(false).toBeTruthy();
52+
done();
53+
}
3654
};
3755
var codeFailed = (serviceFailedEventArgs) => {
3856
codingFailedEventArgs = serviceFailedEventArgs;
@@ -58,26 +76,6 @@ describe('openlayers_AddressMatchService', () => {
5876
return Promise.resolve(new Response(codeSuccessEscapedJson));
5977
});
6078
addressCodeService.code(GeoCodingParams, codeCompleted);
61-
setTimeout(() => {
62-
try {
63-
expect(addressCodeService).not.toBeNull();
64-
expect(codingSuccessEventArgs).not.toBeNull();
65-
expect(codingSuccessEventArgs.type).toBe('processCompleted');
66-
expect(codingSuccessEventArgs.result).not.toBeNull();
67-
expect(codingSuccessEventArgs.result.length).toBe(10);
68-
GeoCodingParams.destroy();
69-
codingSuccessEventArgs = null;
70-
codingFailedEventArgs = null;
71-
done();
72-
} catch (exception) {
73-
console.log("'code'案例失败:" + exception.name + ":" + exception.message);
74-
GeoCodingParams.destroy();
75-
codingFailedEventArgs = null;
76-
codingSuccessEventArgs = null;
77-
expect(false).toBeTruthy();
78-
done();
79-
}
80-
}, 0);
8179
});
8280

8381
it('decode', (done) => {
@@ -87,6 +85,24 @@ describe('openlayers_AddressMatchService', () => {
8785
};
8886
var decodeCompleted = (analyseEventArgs) => {
8987
decodingSuccessEventArgs = analyseEventArgs;
88+
try {
89+
expect(addressDeCodeService).not.toBeNull();
90+
expect(decodingSuccessEventArgs).not.toBeNull();
91+
expect(decodingSuccessEventArgs.type).toBe('processCompleted');
92+
expect(decodingSuccessEventArgs.result).not.toBeNull();
93+
expect(decodingSuccessEventArgs.result.length).toEqual(5);
94+
GeoDeCodingParams.destroy();
95+
decodingFailedEventArgs = null;
96+
decodingSuccessEventArgs = null;
97+
done();
98+
} catch (exception) {
99+
console.log("'decode'案例失败:" + exception.name + ":" + exception.message);
100+
GeoDeCodingParams.destroy();
101+
decodingFailedEventArgs = null;
102+
decodingSuccessEventArgs = null;
103+
expect(false).toBeTruthy();
104+
done();
105+
}
90106
};
91107
var GeoDeCodingParams = new GeoDecodingParameter({
92108
x: 116.31740122415627,
@@ -108,31 +124,24 @@ describe('openlayers_AddressMatchService', () => {
108124
return Promise.resolve(new Response(decodeSuccessEscapedJson));
109125
});
110126
addressDeCodeService.decode(GeoDeCodingParams, decodeCompleted);
111-
setTimeout(() => {
127+
});
128+
it('code_customQueryParam', (done) => {
129+
var codingFailedEventArgs = null, codingSuccessEventArgs = null;
130+
var codeCompleted = (analyseEventArgs) => {
131+
codingSuccessEventArgs = analyseEventArgs;
112132
try {
113-
expect(addressDeCodeService).not.toBeNull();
114-
expect(decodingSuccessEventArgs).not.toBeNull();
115-
expect(decodingSuccessEventArgs.type).toBe('processCompleted');
116-
expect(decodingSuccessEventArgs.result).not.toBeNull();
117-
expect(decodingSuccessEventArgs.result.length).toEqual(5);
118-
GeoDeCodingParams.destroy();
119-
decodingFailedEventArgs = null;
120-
decodingSuccessEventArgs = null;
133+
GeoCodingParams.destroy();
134+
codingSuccessEventArgs = null;
135+
codingFailedEventArgs = null;
121136
done();
122137
} catch (exception) {
123-
console.log("'decode'案例失败:" + exception.name + ":" + exception.message);
124-
GeoDeCodingParams.destroy();
125-
decodingFailedEventArgs = null;
126-
decodingSuccessEventArgs = null;
138+
console.log("'code'案例失败:" + exception.name + ":" + exception.message);
139+
GeoCodingParams.destroy();
140+
codingFailedEventArgs = null;
141+
codingSuccessEventArgs = null;
127142
expect(false).toBeTruthy();
128143
done();
129144
}
130-
}, 0);
131-
});
132-
it('code_customQueryParam', (done) => {
133-
var codingFailedEventArgs = null, codingSuccessEventArgs = null;
134-
var codeCompleted = (analyseEventArgs) => {
135-
codingSuccessEventArgs = analyseEventArgs;
136145
};
137146
var codeFailed = (serviceFailedEventArgs) => {
138147
codingFailedEventArgs = serviceFailedEventArgs;
@@ -154,21 +163,6 @@ describe('openlayers_AddressMatchService', () => {
154163
return Promise.resolve(new Response(codeSuccessEscapedJson));
155164
});
156165
addressCodeService.code(GeoCodingParams, codeCompleted);
157-
setTimeout(() => {
158-
try {
159-
GeoCodingParams.destroy();
160-
codingSuccessEventArgs = null;
161-
codingFailedEventArgs = null;
162-
done();
163-
} catch (exception) {
164-
console.log("'code'案例失败:" + exception.name + ":" + exception.message);
165-
GeoCodingParams.destroy();
166-
codingFailedEventArgs = null;
167-
codingSuccessEventArgs = null;
168-
expect(false).toBeTruthy();
169-
done();
170-
}
171-
}, 0);
172166
});
173167

174168
it('decode_customQueryParam', (done) => {
@@ -178,6 +172,19 @@ describe('openlayers_AddressMatchService', () => {
178172
};
179173
var decodeCompleted = (analyseEventArgs) => {
180174
decodingSuccessEventArgs = analyseEventArgs;
175+
try {
176+
GeoDeCodingParams.destroy();
177+
decodingFailedEventArgs = null;
178+
decodingSuccessEventArgs = null;
179+
done();
180+
} catch (exception) {
181+
console.log("'decode'案例失败:" + exception.name + ":" + exception.message);
182+
GeoDeCodingParams.destroy();
183+
decodingFailedEventArgs = null;
184+
decodingSuccessEventArgs = null;
185+
expect(false).toBeTruthy();
186+
done();
187+
}
181188
};
182189
var GeoDeCodingParams = new GeoDecodingParameter({
183190
x: 116.31740122415627,
@@ -195,20 +202,5 @@ describe('openlayers_AddressMatchService', () => {
195202
return Promise.resolve(new Response(decodeSuccessEscapedJson));
196203
});
197204
addressDeCodeService.decode(GeoDeCodingParams, decodeCompleted);
198-
setTimeout(() => {
199-
try {
200-
GeoDeCodingParams.destroy();
201-
decodingFailedEventArgs = null;
202-
decodingSuccessEventArgs = null;
203-
done();
204-
} catch (exception) {
205-
console.log("'decode'案例失败:" + exception.name + ":" + exception.message);
206-
GeoDeCodingParams.destroy();
207-
decodingFailedEventArgs = null;
208-
decodingSuccessEventArgs = null;
209-
expect(false).toBeTruthy();
210-
done();
211-
}
212-
}, 0);
213205
});
214206
});

test/openlayers/services/FieldServiceSpec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,10 @@ describe('openlayers_FieldService', () => {
186186
}
187187
return Promise.resolve();
188188
});
189+
let count = 0;
189190
service.getFieldStatisticsInfo(fieldStatisticsParameters, (result) => {
191+
count++
190192
serviceResult = result;
191-
});
192-
193-
setTimeout(() => {
194193
try {
195194
expect(service).not.toBeNull();
196195
expect(service.currentStatisticResult).not.toBeNull();
@@ -206,12 +205,14 @@ describe('openlayers_FieldService', () => {
206205
expect(serviceResult.error).not.toBeNull();
207206
expect(serviceResult.error.code).toEqual(404);
208207
expect(serviceResult.error.errorMsg).toBe("数据源World1不存在,获取相应的数据服务组件失败");
209-
done();
208+
if(count === 6){
209+
done();
210+
}
210211
} catch (e) {
211212
console.log("'fail:getFieldStatisticsInfo'案例失败" + exception.name + ":" + exception.message);
212213
expect(false).toBeTruthy();
213214
done();
214215
}
215-
}, 0);
216+
});
216217
});
217218
});

test/test-main-leaflet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import './leaflet/mapping/initMapSpec.js';
1818

1919
import './leaflet/overlay/EchartsLayerSpec.js';
2020
import './leaflet/overlay/graphic/GraphicSpec.js';
21-
// import './leaflet/overlay/GraphicLayerSpec.js';
21+
import './leaflet/overlay/GraphicLayerSpec.js';
2222
import './leaflet/overlay/graphic/CloverStyleSpec';
2323
import './leaflet/overlay/GraphThemeLayerSpec.js';
2424
import './leaflet/overlay/HeatMapLayerSpec.js';

0 commit comments

Comments
 (0)