Make AngularJS 1.0.7 work with Jasmine 2.0

Make AngularJS 1.0.7 work with Jasmine 2.0

During setup of Jasmine 2.0 for AngularJS 1.0.7 application it turned out that they are not compatible. The reason is that Angular 1.0.7 is compatible with the older version of Jasmine – 1.3. And there were several breaking changes in Jasmine private API which was used by AngularJS.There were two ways to fix this issue:
  • Upgrade AngularJS to 1.2.x
  • Fix Jasmine-related stuff in AngularJS 1.0.7
The first path was reasonable, but required much more efforts than the second one. So, we found a way to make it work for old version of AngularJS.


To make a fix we need to change only “src/ngMock/angular-mocks.js” file. It contains all the code responsible for interaction with Jasmine.This gist contains required patch:Note that patch works only for “angular.js” repository. For your project you should replace all paths “src/ngMock/angular-mocks.js” with correct path in your repository. For example, in our project it is located in “spec/javascripts/helpers/angular-mocks.js”.Put this gist into file “patch-angular-mocks.diff” in the root of your git repository. Fix paths for “angular-mocks.js” as noticed above and apply patch with:Now it should work with new Jasmine! This patch works also for Angular 1.0.8.

Notice for Jasmine upgrade

If you want to upgrade Jasmine from 1.x to 2.0, don’t forget to read about breaking changes.