2021-06-15 00:49:18 -07:00
---
id: 587d824f367417b2b2512c59
2021-07-19 16:05:37 +05:30
title: Eseguire test funzionali sugli endpoint API utilizzando Chai-HTTP II
2021-06-15 00:49:18 -07:00
challengeType: 2
forumTopicId: 301592
dashedName: run-functional-tests-on-api-endpoints-using-chai-http-ii
---
# --description--
2021-07-19 16:05:37 +05:30
Come promemoria, questo progetto verrà costruito a partire dalla seguente bozza su [Replit ](https://replit.com/github/freeCodeCamp/boilerplate-mochachai ), o clonato da [GitHub ](https://github.com/freeCodeCamp/boilerplate-mochachai/ ).
2021-06-15 00:49:18 -07:00
# --instructions--
2021-08-25 09:12:11 -07:00
All'interno di `tests/2_functional-tests.js` , modifica il test `'Test GET /hello with your name'` (`// #2` ) per asserire che lo `status` e il `text` della risposta facciano passare i test.
2021-06-15 00:49:18 -07:00
2021-08-25 09:12:11 -07:00
Invia il tuo nome come query URL, aggiungendo `?name=<your_name>` alla rotta. L'endpoint risponde con `'hello <your_name>'` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-19 16:05:37 +05:30
Tutti i test dovrebbero essere superati
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=1').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2021-08-25 09:12:11 -07:00
Dovresti verificare che `res.status` sia 200
2021-06-15 00:49:18 -07:00
```js
(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);
}
);
```
2021-08-25 09:12:11 -07:00
Dovresti verificare che `res.text` == `'hello <your_name>'`
2021-06-15 00:49:18 -07:00
```js
(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--
```js
/**
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.
*/
```