76 lines
2.7 KiB
Markdown
76 lines
2.7 KiB
Markdown
---
|
|
id: 587d824a367417b2b2512c46
|
|
title: JavaScript アサーションがどのように機能するかを学ぶ
|
|
challengeType: 2
|
|
forumTopicId: 301589
|
|
dashedName: learn-how-javascript-assertions-work
|
|
---
|
|
|
|
# --description--
|
|
|
|
これらのチャレンジに取り組むにあたり、以下の方法のうち 1 つを用いてコードを記述します。
|
|
|
|
- [GitHub レポジトリ](https://github.com/freeCodeCamp/boilerplate-mochachai/)をクローンし、ローカル環境でチャレンジを完了させる。
|
|
- [Replit 始動プロジェクト](https://replit.com/github/freeCodeCamp/boilerplate-mochachai)を使用してチャレンジを完了させる。
|
|
- 使い慣れたサイトビルダーを使用してプロジェクトを完了させる。 必ず GitHub リポジトリのすべてのファイルを取り込む。
|
|
|
|
完了したら、プロジェクトの動作デモをどこか公開の場にホストしてください。 そして、`Solution Link` フィールドでデモへの URL を送信してください。
|
|
|
|
# --instructions--
|
|
|
|
`tests/1_unit-tests.js` の中の、`Basic Assertions` スイート内の `#1` に分類されたテストにおいて、テストを合格にする (`true` と評価する必要があります) ために、それぞれの `assert` を `assert.isNull` または `assert.isNotNull` に変更してください。 アサートに渡された引数を変更しないでください。
|
|
|
|
# --hints--
|
|
|
|
すべてのテストに合格する必要があります。
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=0').then(
|
|
(data) => {
|
|
assert.equal(data.state, 'passed');
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
最初のアサーションに対して、正しいメソッドを選ぶ必要があります - `isNull` もしくは `isNotNull` です。
|
|
|
|
```js
|
|
(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);
|
|
}
|
|
);
|
|
```
|
|
|
|
2 番目のアサーションに対して、正しいメソッドを選ぶ必要があります- `isNull` もしくは `isNotNull` です。
|
|
|
|
```js
|
|
(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--
|
|
|
|
```js
|
|
/**
|
|
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.
|
|
*/
|
|
```
|