-
Notifications
You must be signed in to change notification settings - Fork 12
Hawa - Lab 01 #16
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?
Hawa - Lab 01 #16
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,21 @@ | ||
| { | ||
| "rules": { | ||
| "no-console": "off", | ||
| "indent": [ "error", 2 ], | ||
| "quotes": [ "error", "single" ], | ||
| "semi": ["error", "always"], | ||
| "linebreak-style": [ "error", "unix" ] | ||
| }, | ||
| "env": { | ||
| "es6": true, | ||
| "node": true, | ||
| "mocha": true, | ||
| "jasmine": true | ||
| }, | ||
| "ecmaFeatures": { | ||
| "modules": true, | ||
| "experimentalObjectRestSpread": true, | ||
| "impliedStrict": true | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 'use strict'; | ||
|
|
||
| const greet = require('./lib/greet.js'); | ||
| var name = process.argv[2]; | ||
| // console.log(process.argv); | ||
|
|
||
| greet.sayHi(name); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = {}; | ||
| var name = process.argv[2]; | ||
|
|
||
| exports.sayHi = function(name) { | ||
| if(arguments.length === 0) throw new Error('name not provided'); | ||
| console.log(`Hi ${name}!`); | ||
| return `Hi ${name}!`; | ||
| }; | ||
|
|
||
| exports.saySeeYaLater = function(petName) { | ||
| if(arguments.length === 0) throw new Error('pet name not provided'); | ||
| console.log(`See ya later, ${petName}!`); | ||
| return `See ya later, ${petName}!`; | ||
| }; | ||
|
|
||
| exports.sayHi(name); | ||
| exports.saySeeYaLater('Gaara'); | ||
|
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. Since you are already using module.exports to export this greet.js file, it is not necessary to use exports again on lines 18-19. By nature of module.exports, everything within this file is already going to be exported :) You can then invoke both of these methods in index.js and you will still get the expected result. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict'; | ||
|
|
||
| const greet = require('../lib/greet.js'); | ||
| const assert = require('assert'); | ||
| var name = process.argv[2]; | ||
|
|
||
| describe('Greet Module', function() { | ||
| describe('#sayHi', function() { | ||
| it('should return Hi {name}!', function() { | ||
| var result = greet.sayHi(name); | ||
| assert.ok(result === `Hi ${name}!`, 'not equal to Hi hawa!'); | ||
| }); | ||
| it('should throw a missing name error', function() { | ||
| assert.throws(function() { | ||
| greet.sayHi(); | ||
| }, 'error not thrown'); | ||
| }); | ||
| }); | ||
| describe('#saySeeYaLater', function() { | ||
| it('should return See ya later {petName}!', function(){ | ||
| var results = greet.saySeeYaLater('Gaara'); | ||
| assert.ok(results === 'See ya later, Gaara!', 'not equal to See ya later, Gaara!'); | ||
| }); | ||
| it('should throw a missing name error', function(){ | ||
| assert.throws(function(){ | ||
| greet.saySeeYaLater(); | ||
| }, 'error not thrown'); | ||
| }); | ||
| }); | ||
| }); | ||
|
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. Mocha doesn't accept command line arguments so process.argv[2] will always be undefined. A good work around for this would be to set process.argv[2] = 'string' and then you can test that it returns that value specifically. |
||
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 found process.argv[2] to work on the bonus!
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.
I see that you also have a saySeeYaLater( ) in greet.js you'll want to make sure you also invoke that function here in index.js.