Files
freeCodeCamp/curriculum/challenges/chinese-traditional/06-quality-assurance/quality-assurance-and-testing-with-chai/use-assert.isok-and-assert.isnotok.md

2.4 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d824b367417b2b2512c48 使用 Assert.isOk() 和 Assert.isNotOK() 2 301607 use-assert-isok-and-assert-isnotok

--description--

請注意,本項目在這個 Replit 項目的基礎上進行開發。你也可以從 GitHub 上克隆。

isOk() 用來測試值是否爲真值,isNotOk() 用來測試值是否爲假值。

可以在過濾數組中的假值這個挑戰中瞭解更多關於真值和假值的信息。

--instructions--

tests/1_unit-tests.js 中,Basic Assertions 套件中標註爲 #3 的測試下,修改每個 assertassert.isOk()assert.isNotOk(),通過測試(結果應爲 true)。 不要修改傳入斷言的參數。

--hints--

應通過所有測試。

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

應該第一個斷言選擇正確的方法:isOkisNotOk

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

應該第二個斷言選擇正確的方法:isOkisNotOk

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

應該第三個斷言選擇正確的方法:isOkisNotOk

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