94 lines
2.8 KiB
Markdown
94 lines
2.8 KiB
Markdown
![]() |
---
|
||
|
id: 587d824e367417b2b2512c55
|
||
|
title: オブジェクトにプロパティがあるかどうかをテストする
|
||
|
challengeType: 2
|
||
|
forumTopicId: 301604
|
||
|
dashedName: test-if-an-object-has-a-property
|
||
|
---
|
||
|
|
||
|
# --description--
|
||
|
|
||
|
注意点として、このプロジェクトは [Replit](https://replit.com/github/freeCodeCamp/boilerplate-mochachai) の始動プロジェクト、または [GitHub](https://github.com/freeCodeCamp/boilerplate-mochachai/) からクローンされたプロジェクトに基づいて構築されています。
|
||
|
|
||
|
`property` は、実際のオブジェクトに、与えられたプロパティがあることをアサートします。
|
||
|
|
||
|
# --instructions--
|
||
|
|
||
|
`tests/1_unit-tests.js` の中の、`Objects` スイート内の `#16` に分類されたテストにおいて、テストを合格にする (`true` と評価する必要があります) ために、それぞれの `assert` を `assert.property` または `assert.notProperty` に変更してください。 アサートに渡された引数を変更しないでください。
|
||
|
|
||
|
# --hints--
|
||
|
|
||
|
すべてのテストに合格する必要があります。
|
||
|
|
||
|
```js
|
||
|
(getUserInput) =>
|
||
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
|
||
|
(data) => {
|
||
|
assert.equal(data.state, 'passed');
|
||
|
},
|
||
|
(xhr) => {
|
||
|
throw new Error(xhr.responseText);
|
||
|
}
|
||
|
);
|
||
|
```
|
||
|
|
||
|
最初のアサーションに対して、正しいメソッドを選ぶ必要があります - `property` もしくは `notProperty` です。
|
||
|
|
||
|
```js
|
||
|
(getUserInput) =>
|
||
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
|
||
|
(data) => {
|
||
|
assert.equal(
|
||
|
data.assertions[0].method,
|
||
|
'notProperty',
|
||
|
'A car has not wings'
|
||
|
);
|
||
|
},
|
||
|
(xhr) => {
|
||
|
throw new Error(xhr.responseText);
|
||
|
}
|
||
|
);
|
||
|
```
|
||
|
|
||
|
2 番目のアサーションに対して、正しいメソッドを選ぶ必要があります - `property` もしくは `notProperty` です。
|
||
|
|
||
|
```js
|
||
|
(getUserInput) =>
|
||
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
|
||
|
(data) => {
|
||
|
assert.equal(
|
||
|
data.assertions[1].method,
|
||
|
'property',
|
||
|
'planes have engines'
|
||
|
);
|
||
|
},
|
||
|
(xhr) => {
|
||
|
throw new Error(xhr.responseText);
|
||
|
}
|
||
|
);
|
||
|
```
|
||
|
|
||
|
3 番目のアサーションに対して、正しいメソッドを選ぶ必要があります - `property` もしくは `notProperty` です。
|
||
|
|
||
|
```js
|
||
|
(getUserInput) =>
|
||
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
|
||
|
(data) => {
|
||
|
assert.equal(data.assertions[2].method, 'property', 'Cars have wheels');
|
||
|
},
|
||
|
(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.
|
||
|
*/
|
||
|
```
|