test/lib/angular/angular-mocks.js in simple_pvr-0.0.3 vs test/lib/angular/angular-mocks.js in simple_pvr-0.0.4

- old
+ new

@@ -1,8 +1,7 @@ - /** - * @license AngularJS v1.0.1 + * @license AngularJS v1.0.6 * (c) 2010-2012 Google, Inc. http://angularjs.org * License: MIT * * TODO(vojta): wrap whole file into closure during build */ @@ -201,10 +200,34 @@ * * @description * Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed * into it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration * information. + * + * + * <pre> + * describe('$exceptionHandlerProvider', function() { + * + * it('should capture log messages and exceptions', function() { + * + * module(function($exceptionHandlerProvider) { + * $exceptionHandlerProvider.mode('log'); + * }); + * + * inject(function($log, $exceptionHandler, $timeout) { + * $timeout(function() { $log.log(1); }); + * $timeout(function() { $log.log(2); throw 'banana peel'; }); + * $timeout(function() { $log.log(3); }); + * expect($exceptionHandler.errors).toEqual([]); + * expect($log.assertEmpty()); + * $timeout.flush(); + * expect($exceptionHandler.errors).toEqual(['banana peel']); + * expect($log.log.logs).toEqual([[1], [2], [3]]); + * }); + * }); + * }); + * </pre> */ angular.mock.$ExceptionHandlerProvider = function() { var handler; @@ -219,12 +242,12 @@ * @param {string} mode Mode of operation, defaults to `rethrow`. * * - `rethrow`: If any errors are are passed into the handler in tests, it typically * means that there is a bug in the application or test, so this mock will * make these tests fail. - * - `log`: Sometimes it is desirable to test that an error is throw, for this case the `log` mode stores the - * error and allows later assertion of it. + * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log` mode stores an + * array of errors in `$exceptionHandler.errors`, to allow later assertion of them. * See {@link ngMock.$log#assertEmpty assertEmpty()} and * {@link ngMock.$log#reset reset()} */ this.mode = function(mode) { switch(mode) { @@ -405,11 +428,11 @@ * @name angular.mock.TzDate * @description * * *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`. * - * Mock of the Date type which has its timezone specified via constroctor arg. + * Mock of the Date type which has its timezone specified via constructor arg. * * The main purpose is to create Date-like instances with timezone fixed to the specified timezone * offset, so that we can test code that depends on local timezone settings without dependency on * the time zone settings of the machine where the code is running. * @@ -560,11 +583,11 @@ })(); /** * @ngdoc function - * @name angular.mock.debug + * @name angular.mock.dump * @description * * *NOTE*: this is not an injectable instance, just a globally available function. * * Method for serializing common angular objects (scope, elements, etc..) into strings, useful for debugging. @@ -743,11 +766,11 @@ }); }; } // testing controller - var $http; + var $httpBackend; beforeEach(inject(function($injector) { $httpBackend = $injector.get('$httpBackend'); // backend definition common for all tests @@ -1589,13 +1612,33 @@ window.jasmine && (function(window) { afterEach(function() { var spec = getCurrentSpec(); + var injector = spec.$injector; + spec.$injector = null; spec.$modules = null; + + if (injector) { + injector.get('$rootElement').unbind(); + injector.get('$browser').pollFns.length = 0; + } + angular.mock.clearDataCache(); + + // clean up jquery's fragment cache + angular.forEach(angular.element.fragments, function(val, key) { + delete angular.element.fragments[key]; + }); + + MockXhr.$$lastInstance = null; + + angular.forEach(angular.callbacks, function(val, key) { + delete angular.callbacks[key]; + }); + angular.callbacks.counter = 0; }); function getCurrentSpec() { return jasmine.getEnv().currentSpec; } @@ -1608,11 +1651,11 @@ /** * @ngdoc function * @name angular.mock.module * @description * - * *NOTE*: This is function is also published on window for easy access.<br> + * *NOTE*: This function is also published on window for easy access.<br> * *NOTE*: Only available with {@link http://pivotal.github.com/jasmine/ jasmine}. * * This function registers a module configuration code. It collects the configuration information * which will be used when the injector is created by {@link angular.mock.inject inject}. * @@ -1642,12 +1685,16 @@ /** * @ngdoc function * @name angular.mock.inject * @description * +<<<<<<< HEAD * *NOTE*: This is function is also published on window for easy access.<br> * *NOTE*: Only available with {@link http://pivotal.github.com/jasmine/ jasmine}. +======= + * *NOTE*: This function is also published on window for easy access.<br> +>>>>>>> 8dca056... docs(mocks): fix typos * * The inject function wraps a function into an injectable function. The inject() creates new * instance of {@link AUTO.$injector $injector} per test, which is then used for * resolving references. * @@ -1692,11 +1739,11 @@ * * @param {...Function} fns any number of functions which will be injected using the injector. */ window.inject = angular.mock.inject = function() { var blockFns = Array.prototype.slice.call(arguments, 0); - var stack = new Error('Declaration Location').stack; + var errorForStack = new Error('Declaration Location'); return isSpecRunning() ? workFn() : workFn; ///////////////////// function workFn() { var spec = getCurrentSpec(); var modules = spec.$modules || []; @@ -1708,12 +1755,14 @@ } for(var i = 0, ii = blockFns.length; i < ii; i++) { try { injector.invoke(blockFns[i] || angular.noop, this); } catch (e) { - if(e.stack) e.stack += '\n' + stack; + if(e.stack && errorForStack) e.stack += '\n' + errorForStack.stack; throw e; + } finally { + errorForStack = null; } } } - } + }; })(window);