angular controller test

Testing controller with controllerAs

After we’ve seen how to test a service, let’s talk about testing a controller.

angular service unit test

Ok. Let’s talk about javascript real unit-testing…

angularjs directive api pattern

suppose you’re using angular and you have a directive that you pass data to:

<my-chart data="chartData"></my-chart>;

suppose the directive needs to perform some logic when data changes. you’ll probably use $watch:

angular.module('app')
.controller('MainController', function($scope){
    function dataChange(){
        $scope.chartData= {...};
    }
})
.directive('myChart', function(){
    return {
        scope: {data: '='},
        link: function(scope){
            function redraw(){...}
            scope.$watch('data', redraw);
        }
    };
});

undefined object property

If you try to access a non-existing property of an object you’ll get undefined:

var A = {};
console.log(A.a);//undefined
console.log(A);//Object {}

javascript casting

cast primitive variables quite easily