Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc
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"
}
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const greet = require('./lib/greet.js');
let name = process.argv[2];

greet.sayHey(name);
greet.sayBye(name);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see you make use of process.argv[2] for the bonus!

15 changes: 15 additions & 0 deletions lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

module.exports = exports = {};

exports.sayHey = function(name) {
if(arguments.length === 0) throw new Error('no name was provided');
console.log(`what\'s up ${name}!`);
return `what\'s up ${name}!`;
};

exports.sayBye = function(name) {
if(arguments.length === 0) throw new Error('no name was provided');
console.log(`See ya later ${name}!`);
return `See ya later ${name}!`;
};
30 changes: 30 additions & 0 deletions test/greet-test.js
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');
let name = process.argv[2];

if(name === undefined) name = 'jonny';

describe('Test greet file', function() {
describe('#sayHey', function() {
it('should return what\'s up {name}', function() {
assert.ok(greet.sayHey(name) === `what\'s up ${name}!`, `sayHey function does not return what\'s up ${name}`);
});
it('should return missing name error', function() {
assert.throws(function() {
greet.sayHey();
}, 'error not thrown when it should have been');
});
});
describe('#sayBye', function() {
it('should return see ya later {name}', function() {
assert.ok(greet.sayBye(name) === `See ya later ${name}!`, `sayBye function does not return see ya later ${name}!`);
});
it('should return missing name error', function(){
assert.throws(function() {
greet.sayBye();
}, 'error not thrown when it should have been');
});
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your creative work around to test the bonus, to answer your question- mocha does not accept command line arguments. We will be getting into how to test for such instances later this week!