Files
freeCodeCamp/curriculum/challenges/portuguese/06-quality-assurance/quality-assurance-and-testing-with-chai/test-for-truthiness.md

2.8 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d824b367417b2b2512c49 Testar a veracidade 2 301596 test-for-truthiness

--description--

Lembrando que este projeto está sendo construído a partir do Replit, ou pose ser clonado no GitHub.

isTrue() testará o valor booleano true e isNotTrue() passará quando receber qualquer coisa menos o valor booleano de 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');

isFalse() e isNotFalse() também existem e se comportam da mesma forma que seus correspondentes true, exceto porque buscam o valor booleano false.

--instructions--

Em tests/1_unit-tests.js, no teste classificado como #4 e na suíte Basic Assertions, modifique cada assert para assert.isTrue ou para assert.isNotTrue, de maneira que cada teste passe (seja avaliado como true). Não altere os argumentos passados às afirmações.

--hints--

Todos os testes devem passar.

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

Você deve escolher o método correto para a primeira afirmação - isTrue ou 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);
    }
  );

Você deve escolher o método correto para a segunda afirmação - isTrue ou 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);
    }
  );

Você deve escolher o método correto para a terceira afirmação - isTrue ou 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.
*/