In Part 1, you have got a copy of the starter code and taken an initial dive into how the
Now's let turn our focus to the
Recall, the role of a message object is to bundle commands to send to the rover.
Remember with TDD, to first read through the description of the class. Then read through the given tests and think about what each test means for the desired behavior of the class.
Only then should you start coding the
nameis a string that is the name of the message.
commandsis an array of
let commands = [new Command('MODE_CHANGE', 'LOW_POWER'), new Command('STATUS_CHECK')]; let message = new Message('Test message with two commands', commands);
At the same level as
command.spec.js, look for a file called
read the unit tests for the
Message class as described below. After reading about the test, add the necessary code to the
This test description is "throws error if a name is NOT
passed into the constructor as the first parameter". Review the first test
command.spec.js for an example of how this test works.
command.js. Use that to help you write the
message.jsso that your test passes. Refer to the Message Class description above for more details.
The description is "constructor sets name". The test confirms
constructor in the
Message class correctly sets the
name property in a new message object.
The description reads "contains a commands array passed into the constructor as 2nd argument".
This test confirms that the
commands property of a new message object
contains the data passed in from the
Message(name, commands) call.
You are moving onto the red planet now. Be prepared for fewer instructions.
The final class we need to work on is
Rover. Let's check it out in Part 3!