|
@@ -61,7 +61,10 @@ test("request", async () => {
|
|
|
|
|
|
expect(fetch).toBeCalledWith("https://example.com/test?one=two", {
|
|
|
body: '{"foo":"bar"}',
|
|
|
- headers: { "content-type": "application/json", "x-power-by": "test" },
|
|
|
+ headers: {
|
|
|
+ "content-type": "application/json;charset=UTF-8",
|
|
|
+ "x-power-by": "test",
|
|
|
+ },
|
|
|
method: "PUT",
|
|
|
mode: "cors",
|
|
|
});
|
|
@@ -78,7 +81,7 @@ test("name 参数变量替换", async () => {
|
|
|
|
|
|
expect(fetch).toBeCalledWith("https://example.com/test/123/baz", {
|
|
|
body: '{"id":"123","foo":{"bar":"baz"}}',
|
|
|
- headers: { "content-type": "application/json" },
|
|
|
+ headers: { "content-type": "application/json;charset=UTF-8" },
|
|
|
method: "POST",
|
|
|
mode: "cors",
|
|
|
});
|
|
@@ -134,7 +137,10 @@ test("拦截器", async () => {
|
|
|
"https://example.com/test?bar=bar&foo=foo&one=two",
|
|
|
{
|
|
|
body: undefined,
|
|
|
- headers: { "content-type": "application/json", "x-power-by": "test" },
|
|
|
+ headers: {
|
|
|
+ "content-type": "application/json;charset=UTF-8",
|
|
|
+ "x-power-by": "test",
|
|
|
+ },
|
|
|
method: "GET",
|
|
|
mode: "cors",
|
|
|
}
|
|
@@ -157,7 +163,7 @@ test("拦截器元数据", async () => {
|
|
|
request("/test", {}, { meta: { foo: "bar" } });
|
|
|
expect(interceptor.mock.calls[0][0]).toEqual({
|
|
|
body: {},
|
|
|
- headers: { "content-type": "application/json" },
|
|
|
+ headers: { "content-type": "application/json;charset=UTF-8" },
|
|
|
// 拦截到元数据
|
|
|
meta: { foo: "bar" },
|
|
|
method: "POST",
|
|
@@ -167,7 +173,7 @@ test("拦截器元数据", async () => {
|
|
|
|
|
|
expect(fetch).toBeCalledWith("https://example.com/test", {
|
|
|
body: "{}",
|
|
|
- headers: { "content-type": "application/json" },
|
|
|
+ headers: { "content-type": "application/json;charset=UTF-8" },
|
|
|
method: "POST",
|
|
|
mode: "cors",
|
|
|
});
|
|
@@ -192,13 +198,13 @@ test("拦截重试, 用于重新登录等复杂场景", async () => {
|
|
|
// fetch 被调用两次
|
|
|
expect(fetch).toBeCalledWith("https://example.com/test", {
|
|
|
body: '{"time":1}',
|
|
|
- headers: { "content-type": "application/json" },
|
|
|
+ headers: { "content-type": "application/json;charset=UTF-8" },
|
|
|
method: "POST",
|
|
|
mode: "cors",
|
|
|
});
|
|
|
expect(fetch).toBeCalledWith("https://example.com/test", {
|
|
|
body: '{"time":2}',
|
|
|
- headers: { "content-type": "application/json" },
|
|
|
+ headers: { "content-type": "application/json;charset=UTF-8" },
|
|
|
method: "POST",
|
|
|
mode: "cors",
|
|
|
});
|
|
@@ -319,7 +325,7 @@ test("变量替换", async () => {
|
|
|
expect(fetch).toBeCalledWith("https://example.com/test?myId=mock&one=two", {
|
|
|
body: '{"foo":"bar","myId":"mock"}',
|
|
|
headers: {
|
|
|
- "content-type": "application/json",
|
|
|
+ "content-type": "application/json;charset=UTF-8",
|
|
|
"x-power-by": "test",
|
|
|
"my-id": "mock",
|
|
|
},
|