Skip to content
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@kaylynyuh AWESOME attribution provided here - keep that up!

https://nodejs.org/dist/latest-v4.x/docs/api/assert.html#assert_assert_throws_block_error_message
6 changes: 6 additions & 0 deletions lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = function greet(name) {
if (!name) throw new Error('expected name');
return 'hello ' + 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.

@kaylynyuh try using string interpolation, it's super efficient and makes things cleaner and more dynamic. For example:

you have:

return 'hello' + name;

when you can also do:

return `hello ${name}`

};
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@kaylynyuh awesome use of the bugs property to add in your github issues link!

},
"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"
}
}
15 changes: 15 additions & 0 deletions test/greet-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const greet = require('../lib/greet.js');
const assert = require('assert');

describe('testing greet module', function() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@kaylynyuh best practice is to include an additional describe block, inside of this one, that includes the method name - your outer describe block should reference the module that you are testing.

For example:

describe('ModuleName', function() {
  describe('#methodName', function() {
    it('should do stuff', function() {
      // assertion testing goes here
    });
  });
});

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');
});
});