aboutsummaryrefslogtreecommitdiffstats
path: root/test/ScopeSpec.js
diff options
context:
space:
mode:
authorIgor Minar2011-01-25 20:44:44 -0800
committerIgor Minar2011-01-26 15:46:05 -0800
commitf5d08963b0c836b10133a94d03a81254242661eb (patch)
tree14c525d0aa22193e5b1a1f8aa791b96608dc83b2 /test/ScopeSpec.js
parent7a48ee6aa949e8d4338033de8a0c6a079ceb17a3 (diff)
downloadangular.js-f5d08963b0c836b10133a94d03a81254242661eb.tar.bz2
split mocks and create $log and $exceptionHandler mocks
- split mocks between angular-mocks.js and mocks.js - src/angular-mocks.js now contains only mocks that we want to ship - test/mocks.js contains mocks that we use internally for testing angular - created angular.mock namespace - created public $exceptionHandler mock rethrows errors - created public $log mock stores all logs messages in an array that can be accessed to make assertions - internally we now have factory to create $exceptionHandler that we can assert on - internally we also keep track of all messages logged and fail tests if messages were not expected and cleaned up (checked via global beforeEach and afterEach) - updated RakeFile and docs reader.js to point to the new angular-mocks.js location - made real $exceptionHandler and $log factories accessible from tests and simplified their specs - fixed typos in several spec descriptions - added log assertions throughout the test suite
Diffstat (limited to 'test/ScopeSpec.js')
-rw-r--r--test/ScopeSpec.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js
index 8984f605..ab1ba124 100644
--- a/test/ScopeSpec.js
+++ b/test/ScopeSpec.js
@@ -146,30 +146,34 @@ describe('scope/model', function(){
});
describe('$tryEval', function(){
- it('should report error on element', function(){
- var scope = createScope();
+ it('should report error using the provided error handler and $log.error', function(){
+ var scope = createScope(),
+ errorLogs = scope.$service('$log').error.logs;
+
scope.$tryEval(function(){throw "myError";}, function(error){
scope.error = error;
});
expect(scope.error).toEqual('myError');
+ expect(errorLogs.shift()[0]).toBe("myError");
});
it('should report error on visible element', function(){
- var element = jqLite('<div></div>');
- var scope = createScope();
+ var element = jqLite('<div></div>'),
+ scope = createScope(),
+ errorLogs = scope.$service('$log').error.logs;
+
scope.$tryEval(function(){throw "myError";}, element);
expect(element.attr('ng-exception')).toEqual('myError');
expect(element.hasClass('ng-exception')).toBeTruthy();
+ expect(errorLogs.shift()[0]).toBe("myError");
});
it('should report error on $excetionHandler', function(){
- var errors = [],
- errorLogs = [],
- scope = createScope(null, {}, {$exceptionHandler: function(e) {errors.push(e)},
- $log: {error: function(e) {errorLogs.push(e)}}});
+ var scope = createScope(null, {$exceptionHandler: $exceptionHandlerMockFactory},
+ {$log: $logMock});
scope.$tryEval(function(){throw "myError";});
- expect(errors).toEqual(["myError"]);
- expect(errorLogs).toEqual(["myError"]);
+ expect(scope.$service('$exceptionHandler').errors.shift()).toEqual("myError");
+ expect(scope.$service('$log').error.logs.shift()).toEqual(["myError"]);
});
});