fix(curriculum): Strip comments from user code for Use Destructuring Assignment to Extract Values from Objects challenge (#38213)

* fix: strip user code to improve tests

* fix: removed closing section tag messing up tests
This commit is contained in:
Randell Dawson 2020-03-25 05:28:17 -07:00 committed by GitHub
parent 8b0cbd6f83
commit 50f15886b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,13 +41,14 @@ Replace the two assignments with an equivalent destructuring assignment. It shou
```yml
tests:
- text: You should remove the ES5 assignment syntax.
testString: assert(!code.match(/today = HIGH_TEMPERATURES\.today/g) && !code.match(/tomorrow = HIGH_TEMPERATURES\.tomorrow/g))
testString: assert(!removeJSComments(code).match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g))
- text: You should use destructuring to create the <code>today</code> variable.
testString: assert(code.match(/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
testString: assert(removeJSComments(code).match(/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: You should use destructuring to create the <code>tomorrow</code> variable.
testString: assert(code.match(/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
testString: assert(removeJSComments(code).match(/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: <code>today</code> should be equal to <code>77</code> and <code>tomorrow</code> should be equal to <code>80</code>.
testString: assert(today === 77 && tomorrow === 80);
```
</section>
@ -72,6 +73,16 @@ const tomorrow = HIGH_TEMPERATURES.tomorrow;
```
</div>
### After Test
<div id='js-teardown'>
```js
const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
```
</div>
</section>
## Solution