From 11ccb8ad1ba44e77c6aa7fddbbbbc2c0bc42d06a Mon Sep 17 00:00:00 2001 From: Stefanie Hansen Date: Mon, 9 May 2016 18:13:17 -0700 Subject: [PATCH] Completed the assignment, the method within greet.js now greets via command line and tests pass --- .gitignore | 1 + greet.js | 11 +++++++++++ test/greet-test.js | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 .gitignore create mode 100755 greet.js create mode 100644 test/greet-test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/greet.js b/greet.js new file mode 100755 index 0000000..75de9ef --- /dev/null +++ b/greet.js @@ -0,0 +1,11 @@ +(function() { + exports = module.exports = {}; + exports.greet = function(name) { + return 'Hello ' + name; + }; + + if (!module.parent) { + console.log(exports.greet(process.argv.slice(2))); + }; + +})(); diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..a1140e6 --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,16 @@ +const chai = require('chai'); +const expect = chai.expect; +const greeting = require('../greet.js'); + +describe('Greeting test', () => { + it('should return a greeting with the name passed', () => { + expect(greeting.greet('Stefanie')).to.eql('Hello Stefanie'); + }) +}) + +describe('Greeting test via command line utility', () => { + it('should return a greeting with the name passed in the command line', () => { + process.argv = ['node', 'Users/Stefanie/cf/401/class-01/stefanie-hansen/greet.js', 'Stefanie']; + expect(greeting.greet(process.argv.slice(2))).to.eql('Hello Stefanie'); + }) +})