Files
freeCodeCamp/curriculum/challenges/chinese-traditional/06-quality-assurance/quality-assurance-and-testing-with-chai/learn-how-javascript-assertions-work.md

2.2 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d824a367417b2b2512c46 瞭解 JavaScript 斷言的工作原理 2 301589 learn-how-javascript-assertions-work

--description--

你可以採用下面的任意一種方式完成這些挑戰:

完成本項目後,請將一個正常運行的 demo項目演示託管在可以公開訪問的平臺。 然後在 Solution Link 框中提交你的項目 URL。

--instructions--

tests/1_unit-tests.js 文件下 Basic Assertions suite 內註釋爲 #1 的地方,將每一個 assert 更改爲 assert.isNullassert.isNotNull 以使測試通過(應該返回 true)。 不要改變傳入斷言的參數。

--hints--

所有測試都應該通過。

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

請爲第一個斷言選擇正確的方法— isNullisNotNull

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

請爲第二個斷言選擇正確的方法— isNullisNotNull

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