Posts

Showing posts from October, 2015

The Way of Testivus - the tao of unit testing

One of my teammates shared this with the team the other day: The Way of Testivus I love it and want to share it. If you write code, write tests Don’t get stuck on unit testing dogma Embrace unit testing karma Think of code and test as one The test is more important than the unit  The best time to test is when the code is fresh Tests not run waste away An imperfect test today is better than a perfect test someday An ugly test is better than no test  Only fools use no tools Good tests fail Tests prove the code works. Tests catch bugs.  Tests provide a "safety net" so you can make changes to and refactor code and be confident it still works.

angularjs .service() simple mixin approach

We are developing angularjs .services() which have significant common behavior. We want to reuse that code and js inheritance and mixins are options to do that. There are articles out there about this, heres a good one for .factory() which defines a function constructor and more on stack overflow as well as this good post . I took a mixin approach and implemented as follows:     ChildService.$inject = [     'ParentService'     ];     /**      * Service constructor      */     function ChildService(             ParentService) {         // mixin from parent using angular.copy         // note: using copy because angular.extend() does not safely mixin non primitive properties         angular.copy(ParentService, this);         this. doSomething = doSomething;         // local methods (some private, some public)         function doSomething(params) {         }     } I'm copying methods and properties from ParentService to ChildService. This is only sui