Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 15, 2022 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/597e13d424cdaef3affe1ed449ded223 to your computer and use it in GitHub Desktop.
Save codecademydev/597e13d424cdaef3affe1ed449ded223 to your computer and use it in GitHub Desktop.
Codecademy export
// Define a rooster
Rooster = {};
// Return a morning rooster call
Rooster.announceDawn = () => {
return 'cock-a-doodle-doo!';
}
// 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;
const assert = require('assert');
const Rooster = require('../index.js');
describe('Rooster', () => {
describe('.announceDawn', () => {
it('returns a rooster call', () => {
// Setup
const expected = 'cock-a-doodle-doo!';
// Exercise
const actual = Rooster.announceDawn();
// Verify
assert.strictEqual(actual, expected);
})
})
describe('.timeAtDawn', () => {
it('returns its argument as a string', () => {
// Setup
const input = 12;
const expected = '12'
// Exercise
const actual = Rooster.timeAtDawn(input);
// Verify
assert.strictEqual(actual, expected);
})
it('throws a RangeError if passed a number less than 0', () => {
// Setup
const input = -1;
// Exercise / Verify
const actual = () => Rooster.timeAtDawn(input);
assert.throws(actual, RangeError);
})
it('throws a RangeError if passed a number greater than 23', () => {
// Setup
const input = 24;
// Exercise / Verify
const actual = () => Rooster.timeAtDawn(input);
assert.throws(actual, RangeError);
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment