-
-
Save codecademydev/597e13d424cdaef3affe1ed449ded223 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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