2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
|
title: Test if a Value is a String
|
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Test if a Value is a String
|
2018-10-12 15:37:13 -04:00
|
|
|
|
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 'Strings'.
|
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 ``` /** 13 */``` 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
|
|
|
|
|
|
|
|
Check the responses of the error messages if your tests fail, and make sure you understand the types of the parameters being checked by the assertion.
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2019-07-02 07:00:18 +10:00
|
|
|
|
|
|
|
|
The lines in the test should be changed from `assert.fail()` to either `assert.isString()` or `assert.isNotString()`.
|
|
|
|
|
|
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
|
|
|
|
|
/** 13 - #isString asserts that the actual value is a string. **/
|
|
|
|
|
test('#isString, #isNotString', function() {
|
2019-07-24 00:59:27 -07:00
|
|
|
assert.isNotString(Math.sin(Math.PI / 4), 'a float is not a string');
|
2019-07-02 07:00:18 +10:00
|
|
|
assert.isString(process.env.PATH, 'env vars are strings (or undefined)');
|
2019-07-24 00:59:27 -07:00
|
|
|
assert.isString(JSON.stringify({ type: 'object' }), 'a JSON is a string');
|
2019-07-02 07:00:18 +10:00
|
|
|
});
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
|
|
|
|
</details>
|