Files
freeCodeCamp/curriculum/challenges/italian/06-quality-assurance/quality-assurance-and-testing-with-chai/run-functional-tests-on-api-endpoints-using-chai-http-ii.md

2.1 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d824f367417b2b2512c59 Eseguire test funzionali sugli endpoint API utilizzando Chai-HTTP II 2 301592 run-functional-tests-on-api-endpoints-using-chai-http-ii

--description--

Come promemoria, questo progetto verrà costruito a partire dalla seguente bozza su Replit, o clonato da GitHub.

--instructions--

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.

Invia il tuo nome come query URL, aggiungendo ?name=<your_name> alla rotta. L'endpoint risponde con 'hello <your_name>'.

--hints--

Tutti i test dovrebbero essere superati

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
    (data) => {
      assert.equal(data.state, 'passed');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

Dovresti verificare che res.status sia 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);
    }
  );

Dovresti verificare che 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.
*/