提交 2e29d1b4 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io 提交者: 雪洛

test: uploadFile uni.env测试例

上级 0d212e43
...@@ -34,6 +34,13 @@ describe('ExtApi-UploadFile', () => { ...@@ -34,6 +34,13 @@ describe('ExtApi-UploadFile', () => {
await page.waitFor(2000); await page.waitFor(2000);
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
});
it('Check uni.env', async () => {
await page.callMethod('jest_uploadFile_with_uni_env');
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true);
}); });
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备 // 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
...@@ -47,7 +54,9 @@ describe('ExtApi-UploadFile', () => { ...@@ -47,7 +54,9 @@ describe('ExtApi-UploadFile', () => {
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}) })
} }
let shouldTestCookie = false let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
......
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script>
// #ifdef APP // #ifdef APP
import { import {
testInovkeUploadFile, testInovkeUploadFile,
CommonOptions CommonOptions
} from '@/uni_modules/test-invoke-network-api' } from '@/uni_modules/test-invoke-network-api'
// #endif // #endif
export default { export default {
data() { data() {
...@@ -102,6 +102,29 @@ ...@@ -102,6 +102,29 @@
}, },
}) })
}, },
jest_uploadFile_with_uni_env() {
const filePath = `${uni.env.CACHE_PATH}/download/uni-app.png`
uni.downloadFile({
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
filePath: filePath,
success: () => {
uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: filePath,
name: 'file',
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
},
})
},
fail: () => {
this.jest_result = false
}
});
},
jest_set_cookie() { jest_set_cookie() {
uni.request({ uni.request({
url: "https://request.dcloud.net.cn/api/http/header/setCookie", url: "https://request.dcloud.net.cn/api/http/header/setCookie",
...@@ -178,20 +201,20 @@ ...@@ -178,20 +201,20 @@
this.jest_result = false; this.jest_result = false;
}, },
}) })
}, },
jest_uts_module_invoked(){ jest_uts_module_invoked() {
// #ifdef APP // #ifdef APP
testInovkeUploadFile({ testInovkeUploadFile({
success:(res: any)=>{ success: (res : any) => {
console.log("success :", res); console.log("success :", res);
this.jest_result = true this.jest_result = true
}, },
fail:(err: any)=>{ fail: (err : any) => {
console.log("fail :", err); console.log("fail :", err);
this.jest_result = false this.jest_result = false
} }
} as CommonOptions) } as CommonOptions)
// #endif // #endif
} }
} }
} }
...@@ -217,4 +240,4 @@ ...@@ -217,4 +240,4 @@
font-size: 19px; font-size: 19px;
color: #808080; color: #808080;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册