Posts

Getting started with Karma for AngularJS Testing

Image
Introducing Karma A tool called  Karma  is a JavaScript test runner created by the AngularJS team. Jasmine is the testing framework that we talked about in the  getting started with unit testing for AngularJS  post, and Karma provides helpful tools that make it easier to us to call our Jasmine tests whilst we are writing code. We’re going to rebuild the single page calculator app from the last post using Karma for the tests. Installing Karma You can read the full installation instructions  here  or we also summarise them below. The first step is to install Node.js: Install  Node.js NB the documentation states that:  Karma works on the two latest stable versions. That is 0.8.x and 0.10.x at this point.  However, I have Node.js v0.12.x and have yet to run into any problems. Node: For the following commands I assume use of Terminal for Mac or Command Prompt for Windows. Open the Terminal/Command Prompt and enter the following:...

What is a Branch in angularjs code coverage

A branch is where the runtime can choose whether it can take one path or another. Lets take the following example: if ( a ) { Foo (); } if ( b ) { Bar (); } Yay (); When reaching the first line, it can decide if it wants to go inside the body of the  if(a) -statement. Also, it can decide not to do that. At this stage, we've seen two paths already (one branch). The next statement after that gets more interesting. It can go inside the  if  body and execute  Bar . It can also not do that. But remember that we've already had a branch before. The result may vary if  Foo  was called or not. So we end up with four possible paths: Not calling  Foo , not calling  Bar  either Calling  Foo , not calling  Bar Not calling  Foo , calling  Bar Calling both  Foo  and  Bar The last  Yay  is always executed, no matter if  Foo  or  Bar  was called, so that doesn'...

[HTML5] A Beginner's Guide to Using the Application Cache

Introduction It's becoming increasingly important for web-based applications to be accessible offline. Yes, all browsers can cache pages and resources for long periods if told to do so, but the browser can kick individual items out of the cache at any point to make room for other things. HTML5 addresses some of the annoyances of being offline with the  ApplicationCache  interface. Using the cache interface gives your application three advantages: Offline browsing - users can navigate your full site when they're offline Speed - resources come straight from disk, no trip to the network. Resilience - if your site goes down for "maintenance" (as in, someone accidentally breaks everything), your users will get the offline experience The Application Cache (or AppCache) allows a developer to specify which files the browser should cache and make available to offline users. Your app will load and work correctly, even if the user presses the refresh button while th...