Files

2.4 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d824b367417b2b2512c47 Testar se uma variável ou função é definida 2 301602 test-if-a-variable-or-function-is-defined

--description--

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

--instructions--

Em tests/1_unit-tests.js, no teste classificado como #2 e na suíte Basic Assertions, modifique cada assert para assert.isDefined() ou para assert.isUndefined(), 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=1').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 - isDefined ou isUndefined.

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

Você deve escolher o método correto para segunda afirmação - isDefined ou isUndefined.

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

Você deve escolher o método correto para a terceira afirmação - isDefined ou isUndefined.

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(
    (data) => {
      assert.equal(
        data.assertions[2].method,
        'isDefined',
        'A string is not undefined'
      );
    },
    (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.
*/