static get(action, params = {}) {
return new Promise((resolve, reject) => {
fetch(UrlHelper.apiUrl(action, params), {
credentials: 'same-origin'
})
.then(response => {
return Api.checkStatus(resolve, reject, response)
})
.then(([ ok, response ]) => {
return ok ? resolve(response) : reject(response);
});
});
}
我不完全明白在这种情况下我需要测试什么。
我需要在这里测试一下吗?承诺?
答案 0 :(得分:1)
var request = require("request");
describe("firt get api testing", () => {
test("status code", () => {
request("http://your api", function(
error,
response,
body
) {
var obj = JSON.parse(response.body);
expect(response.statusCode).toBe(200);
expect(obj[0].name).toBe("Karthika Sri");
expect(obj[0].name).toMatch(/[a-z]/);
// expect(response.type).toBe("application/json");
console.log("obj", obj[0].name);
});
});
});