提交 b01bec96 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test(getLocation): 优化代码,规避小程序平台

上级 bee1bb12
const PAGE_PATH = "/pages/API/get-location/get-location"; const PAGE_PATH = "/pages/API/get-location/get-location";
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android') const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios') const isIos = platformInfo.startsWith('ios')
const isApp = isAndroid || isIos const isApp = isAndroid || isIos
const isWeb = platformInfo.startsWith('web') const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
describe("get-location", () => { describe("get-location", () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() if(isMP) {
const isMP = platformInfo.startsWith('mp') // 微信上会有权限弹框,暂时屏蔽测试
if(isMP) { it('not support', async () => {
// 微信上会有权限弹框,暂时屏蔽测试 expect(1).toBe(1)
it('not support', async () => { })
expect(1).toBe(1) return
}) }
}
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600) await page.waitFor(600)
}); });
//system 定位 //system 定位
it("system+type=wgs84+success", async () => { it("system+type=wgs84+success", async () => {
await page.setData({ await page.setData({
jest_provider: 'system', jest_provider: 'system',
...@@ -33,11 +33,11 @@ describe("get-location", () => { ...@@ -33,11 +33,11 @@ describe("get-location", () => {
await page.waitFor(async () => { await page.waitFor(async () => {
return await page.data('jest_complete') === true; return await page.data('jest_complete') === true;
}); });
const data = await page.data() const data = await page.data()
const jest_errCode = data['jest_errCode'] const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) { if (jest_errCode > 0) {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number)); expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else { } else {
//判断经纬度是否在正常范围 //判断经纬度是否在正常范围
...@@ -48,10 +48,10 @@ describe("get-location", () => { ...@@ -48,10 +48,10 @@ describe("get-location", () => {
//判断海拔是否正确 //判断海拔是否正确
expect((await page.data())['jest_altitude']).toEqual(expect.any(Number)); expect((await page.data())['jest_altitude']).toEqual(expect.any(Number));
} }
}); });
//system 定位 //system 定位
it("system+type=wgs84+success+geocode=true", async () => { it("system+type=wgs84+success+geocode=true", async () => {
await page.setData({ await page.setData({
jest_provider: 'system', jest_provider: 'system',
...@@ -64,45 +64,45 @@ describe("get-location", () => { ...@@ -64,45 +64,45 @@ describe("get-location", () => {
await page.waitFor(async () => { await page.waitFor(async () => {
return await page.data('jest_complete') === true; return await page.data('jest_complete') === true;
}); });
const data = await page.data() const data = await page.data()
const jest_errCode = data['jest_errCode'] const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) { if (jest_errCode > 0) {
if (isIos) { if (isIos) {
expect((await page.data())['jest_errCode']).toEqual(1505603); expect((await page.data())['jest_errCode']).toEqual(1505603);
} else if (isAndroid) { } else if (isAndroid) {
expect((await page.data())['jest_errCode']).toEqual(1505700); expect((await page.data())['jest_errCode']).toEqual(1505700);
} else { } else {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number)); expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} }
} }
}); });
//system 定位 //system 定位
it("system+type=wgs84+success+altitude=false", async () => { it("system+type=wgs84+success+altitude=false", async () => {
await page.setData({ await page.setData({
jest_provider: 'system', jest_provider: 'system',
jest_type: 'wgs84', jest_type: 'wgs84',
jest_isAltitude: false, jest_isAltitude: false,
jest_isGeocode: true, jest_isGeocode: true,
jest_isHighAccuracy: false jest_isHighAccuracy: false
}) })
await page.callMethod('jestGetLocation') await page.callMethod('jestGetLocation')
await page.waitFor(async () => { await page.waitFor(async () => {
return await page.data('jest_complete') === true; return await page.data('jest_complete') === true;
}); });
const data = await page.data() const data = await page.data()
const jest_errCode = data['jest_errCode'] const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) { if (jest_errCode > 0) {
//如果定位出错 //如果定位出错
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number)); expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else { } else {
expect((await page.data())['jest_altitude']).toEqual(0); expect((await page.data())['jest_altitude']).toEqual(0);
} }
}); });
//system 定位 //system 定位
...@@ -118,8 +118,8 @@ describe("get-location", () => { ...@@ -118,8 +118,8 @@ describe("get-location", () => {
await page.waitFor(async () => { await page.waitFor(async () => {
return await page.data('jest_complete') === true; return await page.data('jest_complete') === true;
}); });
if (isApp) { if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505601); expect((await page.data())['jest_errCode']).toEqual(1505601);
} }
}); });
...@@ -138,7 +138,7 @@ describe("get-location", () => { ...@@ -138,7 +138,7 @@ describe("get-location", () => {
return await page.data('jest_complete') === true; return await page.data('jest_complete') === true;
}); });
const data = await page.data() const data = await page.data()
const jest_errCode = data['jest_errCode'] const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) { if (jest_errCode > 0) {
...@@ -170,8 +170,8 @@ describe("get-location", () => { ...@@ -170,8 +170,8 @@ describe("get-location", () => {
await page.waitFor(async () => { await page.waitFor(async () => {
return await page.data('jest_complete') === true; return await page.data('jest_complete') === true;
}); });
if (isApp) { if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505607); expect((await page.data())['jest_errCode']).toEqual(1505607);
} }
}); });
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册