-
Notifications
You must be signed in to change notification settings - Fork 12
lab files for day 01, modular patterns and testing #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| 'use strict'; | ||
|
|
||
| const greet = require('./lib/greetings.js'); | ||
|
|
||
| process.argv.forEach((val, index) => { | ||
| console.log(`${index}: ${val}`); | ||
| }); | ||
|
|
||
| greet.sayHello('Scott'); | ||
| greet.sayGoodbye(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.sayHello = function(theName) { | ||
| if (arguments.length === 0) throw new Error('No name was given.'); | ||
| return(`Hello, ${theName}.`); | ||
| }; | ||
|
|
||
| exports.sayGoodbye = function() { | ||
| return('Goodbye, it was nice to meet you.'); | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 'use strict'; | ||
|
|
||
| const greet = require('../lib/greetings.js'); | ||
|
|
||
| const assert = require('assert'); | ||
|
|
||
| describe('Greet Module', function () { | ||
| describe('#sayHello', function() { | ||
| it('should return Hello, Scott.', function () { | ||
| var result = greet.sayHello('Scott'); | ||
| assert.ok(result === 'Hello, Scott.', 'Not equal to Hello, Scott.'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#sayGoodbye', function() { | ||
| it('should return Goodbye, it was nice to meet you.', function() { | ||
| var goodbye = 'Goodbye, it was nice to meet you.'; | ||
| assert.ok(goodbye === 'Goodbye, it was nice to meet you.', 'Not equal to Goodbye, it was nice to meet you.'); | ||
| }); | ||
| }); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to throw in some error handling to account for the possibility of no name being passed in. You'll want to make sure to also have tests to take care of this, this could be handled in another it block. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see you used process.argv[2] for the bonus!
Another way you could have implemented this was to attach another method onto the exports object in greetings.js. This method could have a variable set to process.argv[2] that could be passed as an argument which would dynamically generate a name for you. You could then invoke that method on index.js, similarly to how you are already invoking the others :)