我正在尝试调用 graphql 并从 cookie 中获取数据,它在邮递员应用程序中运行良好。但是,当我尝试使用Newman在命令行上运行此邮递员集合时
在终端:
newman run postman_collection.json -e environment.json
然后它给了我错误
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block,
or by rejecting a promise which was not handled with .catch().
The promise rejected with the reason "TypeError: CookieJar.getAll() requires a callback function".]
{
code: 'ERR_UNHANDLED_REJECTION'
}
而Test脚本代码是这样的
pm.test("Get a test data", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.data.createTest.success).to.eql(true);
});
pm.test("Test data cookies set", async function () {
const cookieJar = pm.cookies.jar();
const url = pm.environment.get("service-url");
const cookies = await cookieJar.getAll(url);
const cookieNames = cookies.map(cookie => cookie.name);
pm.expect(cookieNames).to.include("test-token");
pm.expect(cookieNames).to.include("legacy-test-token");
});
所以我认为错误是因为 getAll() 需要一个回调函数,你知道我做错了什么吗?我该如何改进它,你能帮我解决这个问题吗?非常感谢