提交 cb0b098c 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

test: request增加cookie的测试用例

上级 3c34446b
...@@ -76,4 +76,17 @@ describe('ExtApi-Request', () => { ...@@ -76,4 +76,17 @@ describe('ExtApi-Request', () => {
it('Check HEAD', async () => { it('Check HEAD', async () => {
await request(page, 'HEAD'); await request(page, 'HEAD');
}); });
it('Check Set Cookie', async () => {
res = await page.callMethod('jest_set_cookie')
await page.waitFor(500);
res = await page.data('jest_result');
expect(res).toBe(true)
});
it('Check Delete Cookie', async () => {
res = await page.callMethod('jest_delete_cookie')
await page.waitFor(1000);
res = await page.data('jest_result');
expect(res).toBe(true)
});
}); });
...@@ -189,6 +189,7 @@ ...@@ -189,6 +189,7 @@
firstIpv4: false, firstIpv4: false,
success: (res) => { success: (res) => {
console.log('request success', JSON.stringify(res.data)) console.log('request success', JSON.stringify(res.data))
console.log('request success header is :', JSON.stringify(res.header))
uni.showToast({ uni.showToast({
title: '请求成功', title: '请求成功',
icon: 'success', icon: 'success',
...@@ -229,7 +230,61 @@ ...@@ -229,7 +230,61 @@
this.jest_result = false; this.jest_result = false;
}, },
}); });
},
jest_set_cookie() {
uni.request({
url: this.host + "/api/http/header/setCookie",
method: "GET",
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success: () => {
this.jest_cookie_request(true)
},
fail: () => {
this.jest_result = false;
},
});
},
jest_delete_cookie() {
uni.request({
url: this.host + "/api/http/header/deleteCookie",
method: "GET",
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success: () => {
this.jest_cookie_request(false)
},
fail: () => {
this.jest_result = false;
},
});
},
jest_cookie_request(needCookie: boolean) {
uni.request({
url: this.host + "/api/http/header/requestCookie",
method: "GET",
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success: (res) => {
const requestCookie = (res.data as UTSJSONObject).getJSON("data")?.getAny("requestCookie")
console.log("requestCookie ", requestCookie);
if(requestCookie instanceof Array<unknown>){
this.jest_result = needCookie ? requestCookie.length > 0 : requestCookie.length == 0
}else{
this.jest_result = needCookie ? (requestCookie as UTSJSONObject).toMap().size > 0 : (requestCookie as UTSJSONObject).toMap().size == 0
} }
},
fail: () => {
this.jest_result = false;
},
});
},
} }
} }
</script> </script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册