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 assets/scripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";

var Author = new function(name){
this.name = name || "Anonymous";
this.articles = new Array();
}

Author.prototype.writeArticle = function(title){
this.articles.push(title);
};

Author.prototype.listArticles = function(){
return this.name + " has written: " + this.articles.join(", ");
};

exports.Author = Author;

var peter = new Author("Peter");
peter.writeArticle("A Beginners Guide to npm");
peter.writeArticle("Using npm as a build tool");
peter.listArticles();
2 changes: 1 addition & 1 deletion dist/js/bundle.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"watch-css": "nodemon --ext styl --watch ./src/css --exec 'npm run css'",
"watch-js": "nodemon --ext js --watch ./src/js --exec 'npm run js'",
"watch": "npm run watch-html & npm run watch-css & npm run watch-js",
"server": "npm run watch & live-server --port=3000 ./dist"
"server": "npm run watch & live-server --port=3000 ./dist",
"fun": "echo 'NPM is a fun build tool.'",
"lint": "echo '=> linting' && jshint assets/scripts/*.js",
"mocha": "echo '=> testing' && mocha test/"
},
"repository": {
"type": "git",
Expand All @@ -30,7 +33,9 @@
"browserify": "^13.0.0",
"fontify": "0.0.2",
"html-minifier": "^1.1.1",
"jshint": "^2.9.1",
"live-server": "^0.9.1",
"mocha": "^2.4.5",
"stylus": "^0.53.0",
"uglify-js": "^2.6.1"
},
Expand Down
28 changes: 28 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var assert = require("assert");
var Author = require("../assets/scripts/main.js").Author;

describe("Author", function(){
describe("constructor", function(){
it("should have a default name", function(){
var author = new Author();
assert.equal("Anonymous", author.name);
});
});

describe("#writeArticle", function(){
it("should store articles", function(){
var author = new Author();
assert.equal(0, author.articles.length);
author.writeArticle("test article");
assert.equal(1, author.articles.length);
});
});

describe("#listArticles", function(){
it("should list articles", function(){
var author = new Author("Jim");
author.writeArticle("a great article");
assert.equal("Jim has written: a great article", author.listArticles());
});
});
});