2.0 KiB
2.0 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d824f367417b2b2512c59 | 使用 Chai-HTTP II 在 API 端上運行功能測試 | 2 | 301592 | run-functional-tests-on-api-endpoints-using-chai-http-ii |
--description--
請注意,本項目在這個 Replit 項目的基礎上進行開發。你也可以從 GitHub 上克隆。
--instructions--
在 tests/2_functional-tests.js
中,修改 'Test GET /hello with your name'
測試(// #2
),對響應的 status
和 text
使用斷言來通過測試。
通過將 ?name=<your_name>
附加到路由,將你的姓名作爲 URL 查詢發送。 端點響應 'hello <your_name>'
。
--hints--
應通過所有測試。
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
應該測試 res.status
爲 200
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
(data) => {
assert.equal(data.assertions[0].method, 'equal');
assert.equal(data.assertions[0].args[0], 'res.status');
assert.equal(data.assertions[0].args[1], '200');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
應該測試 res.text
== 'hello <your_name>'
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
(data) => {
assert.equal(data.assertions[1].method, 'equal');
assert.equal(data.assertions[1].args[0], 'res.text');
assert.match(data.assertions[1].args[1], /hello [\w\d_-]/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
--solutions--
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/