This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ngMocks): cleanup $inject annotations after each test
this will help in detecting unannotated functions both in apps and angular core in case only part of the tests are run with strictDi
- Loading branch information
1 parent
2ece1c9
commit 0baa17a
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2127,18 +2127,32 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) { | |
if (window.jasmine || window.mocha) { | ||
|
||
var currentSpec = null, | ||
annotatedFunctions, | ||
isSpecRunning = function() { | ||
return !!currentSpec; | ||
}; | ||
|
||
angular.mock.$$annotate = angular.injector.$$annotate; | ||
angular.injector.$$annotate = function(fn) { | ||
if (typeof fn === 'function' && !fn.$inject) { | ||
annotatedFunctions.push(fn); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
shahata
Author
Contributor
|
||
} | ||
return angular.mock.$$annotate.apply(this, arguments); | ||
}; | ||
|
||
|
||
(window.beforeEach || window.setup)(function() { | ||
annotatedFunctions = []; | ||
currentSpec = this; | ||
}); | ||
|
||
(window.afterEach || window.teardown)(function() { | ||
var injector = currentSpec.$injector; | ||
|
||
annotatedFunctions.forEach(function(fn) { | ||
delete fn.$inject; | ||
}); | ||
|
||
angular.forEach(currentSpec.$modules, function(module) { | ||
if (module && module.$$hashKey) { | ||
module.$$hashKey = undefined; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@shahata There was one internal test that errored on this line because annotatedFunctions was undefined. The cause was that the application created a separate injector to get one-off access to ngResource in a base class that was just used as a base class to other classes. We worked around it by not needing to create the injector at all, but I wonder if there's a legitimate bug here.