2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
|
title: Use the Double Equals to Assert Equality
|
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Use the Double Equals to Assert Equality
|
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 'Equality'.
|
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 ``` /** 5 */``` 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 lines in the test should be changed from `assert.fail()` to either `assert.equal()` or `assert.notEqual()`.
|
|
|
|
|
|
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
|
|
|
|
|
/** 5 - .equal(), .notEqual() **/
|
|
|
|
|
// .equal() compares objects using '=='
|
2019-07-24 00:59:27 -07:00
|
|
|
test('#equal, #notEqual', function() {
|
|
|
|
|
assert.equal(12, '12', 'numbers are coerced into strings with == ');
|
|
|
|
|
assert.notEqual({ value: 1 }, { value: 1 }, '== compares object references');
|
|
|
|
|
assert.equal(6 * '2', '12', 'no more hints...');
|
|
|
|
|
assert.notEqual(6 + '2', '12', 'type your error message if you want');
|
2019-07-02 07:00:18 +10:00
|
|
|
});
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
|
|
|
|
</details>
|