Skip to content

Commit

Permalink
Update angular.js, angular-mocks.js, testacular, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Tilley committed Feb 21, 2013
1 parent c312042 commit b6e036d
Show file tree
Hide file tree
Showing 6 changed files with 5,224 additions and 316 deletions.
16 changes: 8 additions & 8 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ module.exports = (grunt) ->
dist:
src: ['build/lib.js']
dest: 'build/lib.min.js'
testacularServer:
local:
configFile: 'test/testacular.conf.js'
autoWatch: true
browsers: ['Chrome', 'PhantomJS']
reporters: ['dots']
runnerPort: 9101
testacular:
unit:
options:
configFile: 'test/testacular.conf.js'
autoWatch: true
browsers: ['Chrome', 'PhantomJS']
reporters: ['dots']
runnerPort: 9101
keepalive: true

grunt.registerTask 'default', ['coffeelint', 'coffee', 'concat', 'uglify']
grunt.registerTask 'test', ['testacularServer']
grunt.registerTask 'test', ['testacular']
110 changes: 86 additions & 24 deletions test/lib/angular-mocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/**
* @license AngularJS v1.1.1
* @license AngularJS v1.1.3
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*
Expand Down Expand Up @@ -203,6 +202,30 @@ angular.mock.$Browser.prototype = {
* 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() {
Expand All @@ -221,8 +244,8 @@ angular.mock.$ExceptionHandlerProvider = function() {
* - `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 throw, 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()}
*/
Expand Down Expand Up @@ -433,6 +456,7 @@ angular.mock.$LogProvider = function() {
* newYearInBratislava.getDate() => 1;
* newYearInBratislava.getHours() => 0;
* newYearInBratislava.getMinutes() => 0;
* newYearInBratislava.getSeconds() => 0;
* </pre>
*
*/
Expand Down Expand Up @@ -489,6 +513,10 @@ angular.mock.$LogProvider = function() {
return self.date.getSeconds();
};

self.getMilliseconds = function() {
return self.date.getMilliseconds();
};

self.getTimezoneOffset = function() {
return offset * 60;
};
Expand Down Expand Up @@ -539,7 +567,7 @@ angular.mock.$LogProvider = function() {
}

//hide all methods not implemented in this mock that the Date prototype exposes
var unimplementedMethods = ['getMilliseconds', 'getUTCDay',
var unimplementedMethods = ['getUTCDay',
'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
Expand All @@ -562,7 +590,7 @@ angular.mock.$LogProvider = function() {

/**
* @ngdoc function
* @name angular.mock.debug
* @name angular.mock.dump
* @description
*
* *NOTE*: this is not an injectable instance, just a globally available function.
Expand Down Expand Up @@ -745,7 +773,7 @@ angular.mock.dump = function(object) {
}
// testing controller
var $http;
var $httpBackend;
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
Expand Down Expand Up @@ -1329,17 +1357,49 @@ function MockXhr() {
* @description
*
* This service is just a simple decorator for {@link ng.$timeout $timeout} service
* that adds a "flush" method.
* that adds a "flush" and "verifyNoPendingTasks" methods.
*/

/**
* @ngdoc method
* @name ngMock.$timeout#flush
* @methodOf ngMock.$timeout
* @description
*
* Flushes the queue of pending tasks.
*/
angular.mock.$TimeoutDecorator = function($delegate, $browser) {

/**
* @ngdoc method
* @name ngMock.$timeout#flush
* @methodOf ngMock.$timeout
* @description
*
* Flushes the queue of pending tasks.
*/
$delegate.flush = function() {
$browser.defer.flush();
};

/**
* @ngdoc method
* @name ngMock.$timeout#verifyNoPendingTasks
* @methodOf ngMock.$timeout
* @description
*
* Verifies that there are no pending tasks that need to be flushed.
*/
$delegate.verifyNoPendingTasks = function() {
if ($browser.deferredFns.length) {
throw Error('Deferred tasks to flush (' + $browser.deferredFns.length + '): ' +
formatPendingTasksAsString($browser.deferredFns));
}
};

function formatPendingTasksAsString(tasks) {
var result = [];
angular.forEach(tasks, function(task) {
result.push('{id: ' + task.id + ', ' + 'time: ' + task.time + '}');
});

return result.join(', ');
}

return $delegate;
};

/**
*
Expand All @@ -1365,15 +1425,9 @@ angular.module('ngMock', ['ng']).provider({
$httpBackend: angular.mock.$HttpBackendProvider,
$rootElement: angular.mock.$RootElementProvider
}).config(function($provide) {
$provide.decorator('$timeout', function($delegate, $browser) {
$delegate.flush = function() {
$browser.defer.flush();
};
return $delegate;
});
$provide.decorator('$timeout', angular.mock.$TimeoutDecorator);
});


/**
* @ngdoc overview
* @name ngMockE2E
Expand Down Expand Up @@ -1623,7 +1677,15 @@ window.jstestdriver && (function(window) {
});

function isSpecRunning() {
return currentSpec && currentSpec.queue.running;
// https://github.com/angular/angular.js/issues/1467#issuecomment-13592399
// return currentSpec && currentSpec.queue.running;
if (window.jasmine) {
return currentSpec && currentSpec.queue.running;
} else if (window.mocha) {
return currentSpec != null;
} else {
return False;
}
}

/**
Expand Down
Loading

0 comments on commit b6e036d

Please sign in to comment.