diff --git a/README.md b/README.md index 0872d0f..6d9f9a0 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,9 @@ For a second bonus point, write a test that makes sure that the arguments are be * Proper Submission: 2pts * mocha/assert Test: 3pts * Use of Modular Pattern/design of greet object/function: 3pts + +Used this site for reference on how to use assert.equal on line 9 of greet-test.js +https://www.sitepoint.com/unit-test-javascript-mocha-chai/ + +Used Node docs for reference on assert.throw +https://nodejs.org/dist/latest-v4.x/docs/api/assert.html#assert_assert_throws_block_error_message diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..ccfe3b8 --- /dev/null +++ b/lib/greet.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = function greet(name) { + if (!name) throw new Error('expected name'); + return 'hello ' + name; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..9968f12 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "lab-01-modular-patterns", + "version": "1.0.0", + "description": "![CF](assets/shield-32x32.png) Lab 01: Modular Patterns and Testing ===", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/kaylynyuh/lab-01-modular-patterns.git" + }, + "author": "yuhkay4@gmail.com", + "license": "MIT", + "bugs": { + "url": "https://github.com/kaylynyuh/lab-01-modular-patterns/issues" + }, + "homepage": "https://github.com/kaylynyuh/lab-01-modular-patterns#readme", + "devDependencies": { + "eslint": "^3.5.0", + "gulp": "^3.9.1", + "gulp-eslint": "^3.0.1", + "gulp-mocha": "^3.0.1", + "mocha": "^3.0.2" + } +} diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..99cd63e --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,15 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('testing greet module', function() { + it('should say hello world', function() { + assert.equal(greet('world'), 'hello world'); + }); + it('should throw missing name error', function() { + assert.throws(function (){ + greet(); + }, 'error thrown'); + }); +});