Browserify Unit Testing

Time for the second part of the small unit testing guide that started with this post. In the first part, we’ve introduced a very basic function that calculated the age of a person based on a parameter that represented the year of birth. Before making the calculation, the parameter was checked to make sure it’s a number and if it wasn’t the function threw an error. Both use cases are small and perfect to have some test written for them so let’s begin.

Continue reading

Browserify Unit Testing

Returning to Javascript is always fun and scary at the same time. Lately I’m working on a web application and I wanted to make the experience less scary so I’ve invested some time to the tools that all the cool kids use, Grunt, NPM etc. Through this process I’ve discovered Browserify and I was so, so, so happy with the way it handles dependencies. At last I was able to divide my code in countless little js files. I had some fun with it until I’ve decided to add unit tests. I’ve already had some minor experience with Jasmine so I started messing around with Grunt to make it run my browserify-based tests. That’s when the hair pulling started.

Continue reading

AngularJS Directives Naming

Having a clear naming plan for you code is always considered a best practice. Especially if you work on languages like Javascript where it’s so easy to make a mistake on the name of an object property and no one will complain until you start debugging your application and spend hours because of a small naming mistake.

Libraries and frameworks like Angular.js will make things easier for you and provide you with a clear way to design your code but you have to respect its rules. Naming element directives properly is one of the very important rules.

Continue reading

AngularJS Modules

The module concept in Angular.js is something that you love when you’re one of these developers who don’t like having global variables in your application. I’m one of these guys. It works by letting you define angular modules and then you can include objects in these modules based on what their functionality is. For example you might want to have a module for all your network services, another for your directives, another for your controllers and so on. Defining these modules and accessing them later from some other part of your code might be a bit confusing because the syntax differences are minor. This tip is all about these two functions in Angular.

Continue reading