freeCodeCamp/curriculum/challenges/italian/06-quality-assurance/quality-assurance-and-testi.../test-for-truthiness.md

2.8 KiB

id title challengeType forumTopicId dashedName
587d824b367417b2b2512c49 Testare la veridicità 2 301596 test-for-truthiness

--description--

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

isTrue() testa per il valore boleano true e isNotTrue() passa per qualsiasi cosa che non sia il valore booleano true.

assert.isTrue(true, 'This will pass with the boolean value true');
assert.isTrue('true', 'This will NOT pass with the string value "true"');
assert.isTrue(1, 'This will NOT pass with the number value 1');

Esistono anche isFalse() e isNotFalse(), si comportano in maniera simile alle loro controparti con true tranne per il fatto che testano per il valore booleano false.

--instructions--

All'interno di tests/1_unit-tests.js sotto il test etichettato con #4 nella suite Basic Assertions, cambia ogni assert con assert.isTrue oppure assert.isNotTrue per fare passare il test (dovrebbe essere uguale a true). Non cambiare gli argomenti passati alle asserzioni.

--hints--

Tutti i test dovrebbero essere superati.

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

Dovresti scegliere il metodo corretto per la prima asserzione - isTrue oppure isNotTrue.

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
    (data) => {
      assert.equal(data.assertions[0].method, 'isTrue', 'True is true');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

Dovresti scegliere il metodo corretto per la seconda asserzione - isTrue oppure isNotTrue.

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
    (data) => {
      assert.equal(
        data.assertions[1].method,
        'isTrue',
        'Double negation of a truthy value is true'
      );
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

Dovresti scegliere il metodo corretto per la terza asserzione - isTrue oppure isNotTrue.

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
    (data) => {
      assert.equal(
        data.assertions[2].method,
        'isNotTrue',
        'A truthy object is not true - neither is a false one'
      );
    },
    (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.
*/