Skip to content

Instantly share code, notes, and snippets.


Marcus Hammarberg marcusoftnet

View GitHub Profile
View writingMocha2.js
describe("Users", function (){
describe("Validation", function (){
it("validates an email address");
it("validates the presence of a name");
it("validates the password");
// and more
describe("Storage", function (){
it("stores an user");
it("retrieves an user by id");
marcusoftnet / should2.js
Last active Aug 29, 2015
should to check for null
View should2.js
var should = require("should");
var myObject = null;
// DON’T
// this will fail with a "TypeError: Cannot read property 'should' of null" error
// DO
// this is the proper way of writing an assertion for null
marcusoftnet / should3.js
Created Feb 2, 2014
forgetting require...
View should3.js
var name = "marcus";
marcusoftnet / callbackex1.js
Last active Aug 29, 2015
Example callback function
View callbackex1.js
function doSomething(p, callback){
// does something using the p parameter
// maybe call some other service
// that takes a long time to complete
// when that is finally completed.
// it calls back
// by just calling the callback function
marcusoftnet / writingCallbacks.js
Created Feb 2, 2014
Writing callbacks without loosing your mind
View writingCallbacks.js
// First I write the call without parameters
// I then adds the parameters
// and the function is just another param...
doSomething(123, function(){});
// I then create two new lines between the curlies
marcusoftnet / mochawriting1.js
Last active Aug 29, 2015
How I write mocha
View mochawriting1.js
// first just write the top level describe function
// now add an empty function to the describe function
describe('Users', function (){});
// add two line breaks and fill the function out
describe('Users', function (){
marcusoftnet / package.json
Last active Aug 29, 2015
demo package.json
View package.json
"name": "Noun.js",
"description": "This is a REST API against the noun part of Merriam-Webster dictionary",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js",
"test" : "./node_modules/mocha/bin/mocha -u bdd -R spec",
"startLocal" : "nodemon -e html app.js"
marcusoftnet / doneMocha.js
Last active Aug 29, 2015
the done parameter in mocha
View doneMocha.js
var should = require("should");
describe("Configuration setup", function () {
it("loads local configuration default", function (done) {
var config = require("../config")();
done(); // tell mocha that we're done and it can process next test
marcusoftnet / should1.js
Last active Aug 29, 2015
should is nice to write almost english with
View should1.js
var should = require("should");
var name = "marcus";
// You could go to town and write almost-english..., 50);
(5), 10).and.within(5, 5);
(99.99), 0.1);
marcusoftnet / example.package.json
Last active Aug 29, 2015
Example scripts node of package.json
View example.package.json
"scripts": {
"start": "node app.js",
"start_stage": "node app.js 4000",
"test" : "mocha -u bdd -R spec",
"test_watch" : "mocha -u bdd -R spec -w"