This is not a “Help I got stuck on step x of the project” problem. This is not a “I did y and my code still won’t work, why?” problem. This is not a “I don’t understand the project” problem.
This is a question seeking clarification on whether or not my solution is viable, and if not, why not.
The project in question is to write a test suite for code pre-written by Codecademy. In order to complete the project I had to watch the helper video.
In the helper video, “Matt” describes that the Exercise part of the test for RangeError is–in this case–part of the Verify part of the same test. Matt deletes the Exercise part. Per Matt, putting the Exercise part of the test in its own section will “get really messy pretty quickly”.
At this point in the video, his code looks as follows. I understand why it works.
it("throws an error if passed a number less than 0", () => {
// Setup
let inputNumber = -1;
let expected = RangeError;
// Verify
assert.throws(() => {
Rooster.timeAtDawn(inputNumber); // Exercise
}, expected);
});
However, as seen below, I refactored his code after watching the video so that it is formatted like the other tests. This also works, at least in the sense that all tests pass. I understand why it works. I understand (or believe) that both versions essentially do the same thing.
it("throws an error if passed a number less than 0", () => {
// Setup
let inputNumber = -1;
let expected = RangeError;
// Exercise
const actual = () => {
Rooster.timeAtDawn(inputNumber);
}
// Verify
assert.throws(actual, expected);
});
To me, what he did is messy. No disrespect, Matt …
My question is/are,
- WHY will putting Execute in its own section get really messy?
- Is the “messy” comment his opinion?
- Is what he did “best practices”? If so, why?
- Was the video released before some feature became available in JavaScript?
- Is my refactor somehow wrong, or “not actually testing the code”?