2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
|
title: Test if an Object has a Property
|
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Test if an Object has a Property
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
|
## Problem Explanation
|
2019-07-02 07:00:18 +10:00
|
|
|
To begin, locate the file "tests/1_unit_tests.js" and scroll to the suite of tests for 'Objects'.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-02 07:00:18 +10:00
|
|
|
This file contains multiple suites of tests for the project, and this challenge requires you to make the tests in ``` /** 16 */``` pass.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
|
|
### Hint 1
|
2019-07-02 07:00:18 +10:00
|
|
|
|
|
|
|
|
The challenge uses objects defined above the tests. Look closely at both, and determine whether the object will have a property or not.
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2019-07-02 07:00:18 +10:00
|
|
|
|
|
|
|
|
Check the error messages to determine if your understanding of the object's properties was correct.
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 3
|
2019-07-02 07:00:18 +10:00
|
|
|
|
|
|
|
|
The lines in the test should be changed from `assert.fail()` to either `assert.property()` or `assert.notProperty()`.
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2019-07-02 07:00:18 +10:00
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
/** 16 - #property asserts that the actual object has a given property. **/
|
|
|
|
|
// Use #property or #notProperty where appropriate
|
|
|
|
|
test('#property, #notProperty', function() {
|
|
|
|
|
assert.notProperty(myCar, 'wings', 'A car has not wings');
|
|
|
|
|
assert.property(airlinePlane, 'engines', 'planes have engines');
|
|
|
|
|
assert.property(myCar, 'wheels', 'Cars have wheels');
|
|
|
|
|
});
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
|
|
|
|
</details>
|