Hi,
I’m currently working through the Rooster Regulation exercise:
https://www.codecademy.com/paths/web-development/tracks/test-driven-development-javascript/modules/learn-mocha-and-assert/projects/rooster-regulation)
In the file index.js provided by the exercise we have an object Rooster defined. Instead of using object literal, Rooster is defined as an empty object. Then its two methods are created and defined one by one.
Finally, at the bottom of the file the Rooster module is exported.
My question:
Why is Rooster not declared as a variable with ‘const’? Like this…
const Rooster = {};
Instead, in the first line of code it goes like this…
// Define a rooster
Rooster = {};
// Return a morning rooster call
Rooster.announceDawn = () => {
return 'moo!';
}
// Return hour as string
// Throws Error if hour is not between 0 and 23 inclusive
Rooster.timeAtDawn = (hour) => {
if (hour < 0 || hour > 23) {
throw new RangeError;
} else {
return hour.toString();
};
}
module.exports = Rooster;
I though that perhaps it’s part of the exercise (find and correct errors in the code provided, etc.) but then the first test I was supposed to write for one of Rooster methods actually finds it and executes it. I know it’s a fail but why is the test even being conducted? Shouldn’t I be presented with ReferenceError stating that Rooster is undefined?
const assert = require('assert');
const Rooster = require('../index');
describe('Rooster', () => {
describe('.announceDawn', () => {
it('returns a rooster call', () => {
const expected = 'cock-a-doodle-doo!';
const actual = Rooster.announceDawn();
assert.strictEqual(actual, expected);
});
});
});
Mocha test result:
1) Rooster .announceDawn returns a rooster call:
AssertionError: 'moo!' === 'cock-a-doodle-doo!'
+ expected - actual
-moo!
+cock-a-doodle-doo!
at Context.it (test/index_test.js:9:14)