Testing constructors

When you need to test what is happening inside a constructor it’s not obvious how to do it, because it looks like you can’t spy the SUT when you haven’t even created an instance.
Well, thanks to JavaScript’s prototypal nature you can spy on the prototype object directly, just like you would do with any instance:

Cordova projects and npm modules

It may sound obvious but I did it wrong for a while…
When you create a Cordova (Phonegap) application and you want to use npm modules don’t add them within the www folder, use the Cordova project root instead, otherwise the generated node_modules folder will get compiled and added to your build.
The final project structure (as of Cordova 4.0) should look something like this:

+---MyCordovaApp
|   \---hooks
|   \---node_modules
|   \---platforms
|   \---plugins
|   \---www
|   \---config.xml
|   \---package.json // npm project config file
|   \---gulpfile.js // Gulp config file
|   \---karma.conf.js // Karma test runner config file

The node_modules folder is safe here, it won’t be added to the app build.
The only thing that you have to bear in mind is that configuration files paths have to be prefixed with www.

ng-click and stopPropagation()

I have a calendar grid where each grid cell has an ng-click handler that takes me to the day’s detail view.
At the same time, each grid cell can have an indeterminate amount of events associated, each with an ng-click handler associated that displays the selected event details on a popover.

As you can see there’s a conflict here. When you click on a calendar event there will be two ng-click handlers executed (because the event is bubbling), one will display the popover and the other one will go to the day’s detail view. Not what we want.
Thankfully ng-click scope exposes the $event property, which is the DOM event being propagated.
You can use the DOM event stopPropagation() method to stop event propagation.

Related: