Files

2.7 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d824b367417b2b2512c49 測試真實性 2 301596 test-for-truthiness

--description--

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

isTrue() 僅當給出的值爲 Boolean 的 true 時可以通過測試;isNotTrue() 則會在給出除 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()isNotFalse() 同樣存在,與上面提到的兩個方法類似,只不過它們針對值爲 false 的布爾值。

--instructions--

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

--hints--

應通過所有測試。

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

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

(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);
    }
  );

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

(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);
    }
  );

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

(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.
*/