找出这段生成测试中的契约验证缺口。 async function verifyCreated (response) {
const body = await response .json ();
if ( typeof body .id !== "string" ) {
throw new Error ( "missing order id" );
}
return true ;
}
查看答案
上一道练习 审查生成的创建订单端点 审查AI代码
问问你的AI 让你的AI把这段代码改成引导式找错练习。
Claude ChatGPT 复制提示词 I am reading "找出这段生成测试中的契约验证缺口。" on CodeWiki (https://codewiki.com/zh/practice/spotbug/backend/api-first/spot-body-only-verification/).
Context (verbatim from the page):
"""
async function verifyCreated(response) {
const body = await response.json();
if (typeof body.id !== "string") {
throw new Error("missing order id");
}
return true;
}
"""
Introduce three subtle bugs into the example above and let me find them. Reveal each answer only after I have guessed.
Answer in 中文. Keep code examples in javascript. Where you are unsure, say so.