aboutsummaryrefslogtreecommitdiffstats
path: root/test/testabilityPatch.js
diff options
context:
space:
mode:
authorMisko Hevery2011-10-17 16:56:56 -0700
committerMisko Hevery2011-11-14 16:39:31 -0800
commit48697a2b86dbb12ea8de64cc5fece7caf68b321e (patch)
tree1fa50659f0bb5de2640dea2a2e5bb5628f2bb14a /test/testabilityPatch.js
parent93b777c916ccff243c5a6080bf5f39860ac7bf39 (diff)
downloadangular.js-48697a2b86dbb12ea8de64cc5fece7caf68b321e.tar.bz2
refactor(injector): turn scope into a service
- turn scope into a $rootScope service. - injector is now a starting point for creating angular application. - added inject() method which wraps jasmine its/beforeEach/afterEach, and which allows configuration and injection of services. - refactor tests to use inject() where possible BREAK: - removed angular.scope() method
Diffstat (limited to 'test/testabilityPatch.js')
-rw-r--r--test/testabilityPatch.js99
1 files changed, 73 insertions, 26 deletions
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index a8b1c06b..3d964149 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -17,7 +17,7 @@ if (window.jstestdriver) {
if (isElement(arg)) {
arg = sortedHtml(arg);
} else if (isObject(arg)) {
- if (arg.$eval == Scope.prototype.$eval) {
+ if (isFunction(arg.$eval) && isFunction(arg.$apply)) {
arg = dumpScope(arg);
} else {
arg = toJson(arg, true);
@@ -79,9 +79,79 @@ beforeEach(function() {
$logMock.warn.logs = [];
$logMock.info.logs = [];
$logMock.error.logs = [];
+
+ resetAngularPublic()
});
-afterEach(function() {
+function inject(){
+ var blockFns = sliceArgs(arguments);
+ return function(){
+ var spec = this;
+ angular.forEach(blockFns, function(fn){
+ fn.$inject = inferInjectionArgs(fn);
+ if (equals(fn.$inject, [])) {
+ fn.apply(spec);
+ } else if (equals(fn.$inject, ['service'])) {
+ if (spec.$injector) {
+ throw Error('$injector already created for this test');
+ }
+ if (!spec.$service) {
+ spec.$service = function(name, fn) {
+ if (fn) { spec.$service[name] = fn; }
+ return spec.$service[name];
+ }
+ spec.$service.alias = function (name, alias) {
+ spec.$service(alias, extend(function(x){ return x; }, {$inject:[name]}));
+ };
+ forEach(angularService, function(value, key){
+ spec.$service(key, value);
+ });
+ }
+ fn.call(spec, spec.$service);
+ } else {
+ if (!spec.$injector) {
+ spec.$injector = angular.injector(spec.$service);
+ }
+ spec.$injector.invoke(spec, fn);
+ }
+ });
+ };
+}
+
+/**
+ * This method republishes the public angular API. It should probably be cleaned up somehow.
+ * //TODO: remove this method and merge it with the angularPublic.js class
+ */
+function resetAngularPublic() {
+ extend(angular, {
+ 'element': jqLite,
+ 'compile': compile,
+ 'copy': copy,
+ 'extend': extend,
+ 'equals': equals,
+ 'forEach': forEach,
+ 'noop': noop,
+ 'bind': bind,
+ 'toJson': toJson,
+ 'fromJson': fromJson,
+ 'identity':identity,
+ 'injector': createInjector,
+ 'isUndefined': isUndefined,
+ 'isDefined': isDefined,
+ 'isString': isString,
+ 'isFunction': isFunction,
+ 'isObject': isObject,
+ 'isNumber': isNumber,
+ 'isArray': isArray
+ });
+}
+
+resetAngularPublic();
+
+afterEach(inject(function($rootScope) {
+ // release the injector
+ dealoc($rootScope);
+
// check $log mock
forEach(['error', 'warn', 'info', 'log'], function(logLevel) {
if ($logMock[logLevel].logs.length) {
@@ -104,7 +174,7 @@ afterEach(function() {
});
clearJqCache();
-});
+}));
function clearJqCache() {
var count = 0;
@@ -140,29 +210,6 @@ function dealoc(obj) {
}
}
-extend(angular, {
- 'element': jqLite,
- 'compile': compile,
- 'scope': createScope,
- 'copy': copy,
- 'extend': extend,
- 'equals': equals,
- 'forEach': forEach,
- 'noop':noop,
- 'bind':bind,
- 'toJson': toJson,
- 'fromJson': fromJson,
- 'identity':identity,
- 'injector': createInjector,
- 'isUndefined': isUndefined,
- 'isDefined': isDefined,
- 'isString': isString,
- 'isFunction': isFunction,
- 'isObject': isObject,
- 'isNumber': isNumber,
- 'isArray': isArray
-});
-
function sortedHtml(element, showNgClass) {
var html = "";