freeCodeCamp/curriculum/challenges/chinese/06-quality-assurance/quality-assurance-and-testi.../learn-how-javascript-assert...

2.2 KiB
Raw Blame History

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