mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-01 15:02:09 +08:00
refactor(curriculum): replace greeting bot regex tests with helpers (#69132)
This commit is contained in:
+7
-2
@@ -21,19 +21,24 @@ console.log("Hello, World!");
|
||||
|
||||
Add a `console.log()` statement that outputs the string `"Hi there!"` to the console. Don't forget your quotes around the message!
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `console.log()` statement in your code.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /console\.log(.*)/);
|
||||
assert.isNotEmpty(logSpy.calls);
|
||||
```
|
||||
|
||||
Your `console` statement should have the message `"Hi there!"`. Don't forget the quotes.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /console\.log\((['"])Hi\s+there!\1\);?/);
|
||||
assert.deepInclude(logSpy.calls, ["Hi there!"]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
+8
-2
@@ -13,18 +13,24 @@ It is time to add a second message from the bot.
|
||||
|
||||
Add another `console.log` statement to output the message `"I am excited to talk to you."` to the console.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a second `console.log()` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 2);
|
||||
assert.lengthOf(logSpy.calls, 2);
|
||||
```
|
||||
|
||||
Your `console` statement should have the message `"I am excited to talk to you."`. Don't forget the quotes.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /("|')I\s+am\s+excited\s+to\s+talk\s+to\s+you.\1/);
|
||||
assert.deepInclude(logSpy.calls, ["I am excited to talk to you."]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
+3
-1
@@ -36,7 +36,9 @@ assert.isNotNull(bot);
|
||||
You should use the `let` keyword to declare the variable.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /let\s+bot;?/g);
|
||||
const explorer = await __helpers.Explorer(code);
|
||||
const { bot } = explorer.variables;
|
||||
assert.isTrue(bot?.matches('let bot'));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
+8
-2
@@ -11,18 +11,24 @@ Now, it is time to add another message from the bot.
|
||||
|
||||
Add another `console` statement to the code that logs the message `"Allow me to introduce myself."`.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a third `console.log()` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 3);
|
||||
assert.lengthOf(logSpy.calls, 3);
|
||||
```
|
||||
|
||||
Your `console` statement should have the message `"Allow me to introduce myself."`. Don't forget the quotes.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /("|')Allow\s+me\s+to\s+introduce\s+myself.\1/);
|
||||
assert.deepInclude(logSpy.calls, ["Allow me to introduce myself."]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
+7
-1
@@ -28,6 +28,12 @@ Assign this value to the `botIntroduction` variable.
|
||||
|
||||
Then, log the `botIntroduction` variable to the console.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `botIntroduction`.
|
||||
@@ -51,7 +57,7 @@ assert.equal(botIntroduction, "My name is teacherBot.");
|
||||
You should have a fourth `console.log()` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 4);
|
||||
assert.lengthOf(logSpy.calls, 4);
|
||||
```
|
||||
|
||||
Your `console` statement should output the `botIntroduction` variable.
|
||||
|
||||
+7
-1
@@ -17,6 +17,12 @@ Assign this value to the `botLocationSentence` variable.
|
||||
|
||||
Then, log the value of `botLocationSentence` to the console.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `botLocationSentence` variable.
|
||||
@@ -40,7 +46,7 @@ assert.equal(botLocationSentence, "I live in the universe.");
|
||||
You should have a `console` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 5);
|
||||
assert.lengthOf(logSpy.calls, 5);
|
||||
```
|
||||
|
||||
Your `console` statement should output the `botLocationSentence` variable.
|
||||
|
||||
+7
-1
@@ -17,6 +17,12 @@ Assign the resulting string to the `nicknameIntroduction` variable.
|
||||
|
||||
Then, log the value of `nicknameIntroduction` to the console.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `nicknameIntroduction`.
|
||||
@@ -40,7 +46,7 @@ assert.strictEqual(nicknameIntroduction, "My nickname is professorBot.");
|
||||
You should have a `console` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 6);
|
||||
assert.lengthOf(logSpy.calls, 6);
|
||||
```
|
||||
|
||||
You should log the value of `nicknameIntroduction` to the console.
|
||||
|
||||
+7
-1
@@ -17,6 +17,12 @@ Assign the result to the `newNicknameGreeting` variable.
|
||||
|
||||
Then, log the value of `newNicknameGreeting` to the console.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `newNicknameGreeting`.
|
||||
@@ -40,7 +46,7 @@ assert.strictEqual(newNicknameGreeting, "I love my nickname but I wish people wo
|
||||
You should have a `console` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 7);
|
||||
assert.lengthOf(logSpy.calls, 7);
|
||||
```
|
||||
|
||||
You should log the value of `newNicknameGreeting` to the console.
|
||||
|
||||
+7
-1
@@ -15,6 +15,12 @@ Assign the result to the `favoriteSubjectSentence` variable.
|
||||
|
||||
Then, log the value of `favoriteSubjectSentence` to the console.
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable called `favoriteSubjectSentence`.
|
||||
@@ -38,7 +44,7 @@ assert.strictEqual(favoriteSubjectSentence, "My favorite subject is Computer Sci
|
||||
You should have a `console` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 8);
|
||||
assert.lengthOf(logSpy.calls, 8);
|
||||
```
|
||||
|
||||
You should log the value of `favoriteSubjectSentence` to the console.
|
||||
|
||||
+8
-3
@@ -11,19 +11,24 @@ For the final step, you will log the bot's message of `"Well, it was nice to tal
|
||||
|
||||
And with that, your greeting bot is complete!
|
||||
|
||||
# --before-each--
|
||||
|
||||
```js
|
||||
const logSpy = __helpers.spyOn(console, 'log');
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `console` statement in your code.
|
||||
|
||||
```js
|
||||
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 9);
|
||||
assert.lengthOf(logSpy.calls, 9);
|
||||
```
|
||||
|
||||
Your `console` statement should log the string `"Well, it was nice to talk to you. Have a nice day!"`.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /console\.log\s*\(\s*["']Well\s*,\s*it\s*was\s*nice\s*to\s*talk\s*to\s*you\s*\.\s*Have\s*a\s*nice\s*day\s*!["']\s*\)\s*/
|
||||
);
|
||||
assert.deepInclude(logSpy.calls, ["Well, it was nice to talk to you. Have a nice day!"]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
Reference in New Issue
Block a user