FAQ: Learn TDD With Mocha - Refactor I

This community-built FAQ covers the “Refactor I” exercise from the lesson “Learn TDD With Mocha”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn JavaScript Unit Testing

FAQs on the exercise Refactor I

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

It seems to me that refactoring the test script from

assert.equal(Phrase.initials('Nelson Mandela'), 'NM’);


const inputName = 'Nelson Mandela';
const expectedInitials = 'NM';
const result = Phrase.initials(inputName);
assert.equal(result, expectedInitials);

is an unnecessary step to take. Why not using the “setup, exercise, and verification” structure from the very beginning of writing the test script?

About the setup part : wouldn’t that be more efficient to gather all of the setup value in one place?
For exemple : index_test_setup_0.js :
person = {
name : [ ‘Winston’, ‘Leonard’, ‘Spencer-Churchill’ ]
, lastName : ‘Churchill’
, fullName : ‘Winston Churchill’
, birth : [ 30, 11, 1874 ]
, …
*Testing */
, initials : ‘WC’
, fullBirthDate : ‘30 novembre 1874’
, …

module.exports = person;
So we can have another file index_test_setup_1.js with some other setup to check if the tests result are actually thorough rather than factual?
(PS : I’m french, so i hope it’s clear enough.)

Hi! This is not a question, but it would be fine to include in the description exercise the expected variables names expectedResult, inputArray, result. Another option can be to add them to the hint, because if students could write just expected instead expectedResult the exercise marks wrong.


I have encountered the same issues not only on this exercise but on many other exercises even if the programs were right. I am starting to lose keep my motivation as I progressed further on the course because the advanced topic does not get covered thoroughly.

1 Like

Same here, I wrote my setup as follow:

      const inputArray = [1,2,3];
      const expectedResult = 6;

Which did not pass the checkpoint, but passed the test.
Upon checking the solution, I reversed them in order:

      const expectedResult = 6;
      const inputArray = [1,2,3];

Then I passed the checkpoint. Seems to me like this validation is a bit strict and should be loosened up: if the test passes, we should be able to complete the exercise.