From 33f8459ae9de1bee78042e4675aee2c8ee6b82d3 Mon Sep 17 00:00:00 2001 From: Britt Dawn Date: Mon, 5 Dec 2016 23:15:42 -0800 Subject: [PATCH] Adding greet function and Mocha tests for lab 1. Bonus attempted. --- index.js | 5 +++++ lib/greet.js | 11 +++++++++++ test/greet-test.js | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 index.js create mode 100644 lib/greet.js create mode 100644 test/greet-test.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..be7302a --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +'use strict'; + +const greeting = require('./lib/greet.js'); + +greeting.greet(process.argv[2]); diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..82ac030 --- /dev/null +++ b/lib/greet.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = exports = {}; + +exports.greet = function(name) { + console.log(`hello ${name}`); + if (!arguments.length) throw new Error('name not provided'); + return `hello ${name}!`; +}; + +console.log('hello', process.argv[2]); diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..47c6e5b --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,19 @@ +'use strict'; + +const greeting = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greeting Module', function() { + describe('#greet', function() { + it('should return hello and name if input in command line', function() { + var inputName = process.argv[2]; + let result = greeting.greet(inputName); + assert.ok(result === `hello ${inputName}!`, 'but not equal to hello and input name.'); + }); + it('should throw an undefined if name argument is not passed in command line', function() { + assert.throws(function() { + greeting.greet(); + }, 'error not thrown'); + }); + }); +});