Using Mocha and Chai for unit tests in Node JS projects

ref – https://ubuverse.com/introduction-to-node-js-api-unit-testing-with-mocha-and-chai/ https://scotch.io/tutorials/test-a-node-restful-api-with-mocha-and-chai https://gist.github.com/yoavniran/1e3b0162e1545055429e#mocha https://gist.github.com/yoavniran/1e3b0162e1545055429e#chai Creating the Directory mkdir mocha-chai-demo cd mocha-chai-demo Setting up the package.json in directory /mocha-chai-demo: npm init use defualt for all the options. You will then have a package.json file created, which looks something like this: package name: (mocha-chai-demo) tdd-for-node version: (1.0.0) description: test driven dev for node entry point: […]

Different ways of creating Objects, Object literal vs Object instances

Object.create()

This method creates a new object extending the prototype object passed as a parameter. var b = {} This is equivalent to Object.create(null) method, using a null prototype as an argument. Using function constructor with new

es6 classes

Singleton pattern

literal vs instances https://www.internalpointers.com/post/object-literals-vs-constructors-javascript

You have just created a […]

recursive divide and conquer on arrays

Quick sort version The divide and conquer recursion on an array occurs when we have dubbed a mid, then recursively go into the left side of the array. Then, the right side. We leave the middle element. Thus we apply recursion on low to (mid-1) print mid (mid+1) to high But how? We recursive into […]

JS classes support 3 kinds of methods

https://scotch.io/tutorials/better-javascript-with-es6-pt-ii-a-deep-dive-into-classes review: Javascript Prototype Class Constructors

Static methods Static methods are methods on the constructor function itself, which are not available on instances of the class. You define them by using the static keyword.

Prototype methods Any method that isn’t a constructor or a static method is prototype method. The name comes from […]