Skip to content

Instantly share code, notes, and snippets.

@cris
Created August 10, 2014 23:10
Show Gist options
  • Save cris/11427a86e3396e6bc61b to your computer and use it in GitHub Desktop.
Save cris/11427a86e3396e6bc61b to your computer and use it in GitHub Desktop.
Patch for AngularJS 1.0.7(1.0.8) to make it compatible with Jasmine 2.0
diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js
index 41217c7..fe09bc6 100644
--- a/src/ngMock/angular-mocks.js
+++ b/src/ngMock/angular-mocks.js
@@ -1635,13 +1635,28 @@ window.jstestdriver && (function(window) {
window.jasmine && (function(window) {
+ var currentSpec = null,
+ isSpecRunning = function() {
+ return !!currentSpec;
+ };
+
- afterEach(function() {
- var spec = getCurrentSpec();
- var injector = spec.$injector;
+ (window.beforeEach || window.setup)(function() {
+ currentSpec = this;
+ });
- spec.$injector = null;
- spec.$modules = null;
+ (window.afterEach || window.teardown)(function() {
+ var injector = currentSpec.$injector;
+
+ angular.forEach(currentSpec.$modules, function(module) {
+ if (module && module.$$hashKey) {
+ module.$$hashKey = undefined;
+ }
+ });
+
+ currentSpec.$injector = null;
+ currentSpec.$modules = null;
+ currentSpec = null;
if (injector) {
injector.get('$rootElement').unbind();
@@ -1664,12 +1679,7 @@ window.jasmine && (function(window) {
});
function getCurrentSpec() {
- return jasmine.getEnv().currentSpec;
- }
-
- function isSpecRunning() {
- var spec = getCurrentSpec();
- return spec && spec.queue.running;
+ return currentSpec;
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment