diff --git a/.travis.yml b/.travis.yml index b4e1f9e..24b1d6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ -language: node_js -node_js: - - "0.10" -branches: - only: - - master -before_script: - - npm install -g grunt-cli -after_success: - - npm run coveralls +language: node_js +node_js: + - "0.12" +branches: + only: + - master +before_script: + - npm install -g grunt-cli +after_success: + - npm run coveralls diff --git a/stop-angular-overrides.js b/stop-angular-overrides.js index 338cd47..fa77031 100644 --- a/stop-angular-overrides.js +++ b/stop-angular-overrides.js @@ -25,9 +25,6 @@ // proxy .filter calls to the new module var _filter = angular.bind(m, m.filter); m.filter = function (name, fn) { - if (!fn) { - return _filter(name); - } if (existingFilters[name]) { throw new Error('Angular filter ' + name + ' already exists'); } @@ -37,15 +34,12 @@ // proxy .controller calls to the new module var _controller = angular.bind(m, m.controller); - m.controller = function (name, deps) { - if (!deps) { - return _controller(name); - } + m.controller = function (name, fn) { if (existingControllers[name]) { throw new Error('Angular controller ' + name + ' already exists'); } existingControllers[name] = true; - return _controller(name, deps); + return _controller(name, fn); }; return m; diff --git a/test/test.js b/test/test.js index fab6aa9..e9cf05b 100644 --- a/test/test.js +++ b/test/test.js @@ -26,6 +26,12 @@ QUnit.test('loading angular', function () { QUnit.func(angular.module, 'angular.module is an object'); }); +QUnit.test('angular check', function () { + QUnit.throws(function() { + benv.require('../stop-angular-overrides.js'); + }, 'Missing angular'); +}); + QUnit.test('angular.bind', function () { var angular = benv.require('../bower_components/angular/angular.js', 'angular'); QUnit.func(angular.bind, 'angular.bind is a function'); @@ -48,6 +54,53 @@ QUnit.test('last module overrides by default', function () { QUnit.equal(angular.module('A'), second, 'A -> second module'); }); +QUnit.test('last controller overrides by default', function () { + var angular = benv.require('../bower_components/angular/angular.js', 'angular'); + + var module = angular.module('A', []); + var First = function () { + this.name = 'first'; + }; + var Second = function () { + this.name = 'second'; + }; + + module.controller('aController', First); + module.controller('aController', Second); + + var $controller = angular.injector(['ng', 'A']).get('$controller'); + var pseudoScope = $controller('aController', {$scope: {}}); + QUnit.equal(pseudoScope.name, 'second', 'aController -> second module'); + + module.controller('aController'); + $controller = angular.injector(['ng', 'A']).get('$controller'); + + QUnit.throws(function() { + $controller('aController', {$scope: {}}); + }, 'Argument \'aController\' is not a function, got undefined'); +}); + +QUnit.test('last filter overrides by default', function () { + var angular = benv.require('../bower_components/angular/angular.js', 'angular'); + + var module = angular.module('A', []); + var firstFilter = function () {}; + var secondFilter = function () {}; + + module.filter('aFilter', function () { return firstFilter; }); + module.filter('aFilter', function () { return secondFilter; }); + + var $filter = angular.injector(['ng', 'A']).get('$filter'); + var loadedFilter = $filter('aFilter'); + QUnit.equal(loadedFilter, secondFilter, 'aFilter -> secondFilter'); + + module.filter('aFilter'); + + QUnit.throws(function() { + angular.injector(['ng', 'A']).get('$filter'); + }, 'Error'); +}); + QUnit.test('stop angular override', function () { var angular = benv.require('../bower_components/angular/angular.js', 'angular'); benv.require('../stop-angular-overrides.js'); @@ -81,3 +134,31 @@ QUnit.test('stop angular filter override', function () { angular.module('A2', []).filter('f', function () {}); }, 'Error'); }); + + +QUnit.test('stops controller overrides with undefined', function () { + var angular = benv.require('../bower_components/angular/angular.js', 'angular'); + benv.require('../stop-angular-overrides.js'); + + var module = angular.module('A', []); + + module.controller('aController', function () {}); + + QUnit.throws(function() { + module.controller('aController'); + }, 'Error'); +}); + +QUnit.test('stops filter overrides with undefined', function () { + var angular = benv.require('../bower_components/angular/angular.js', 'angular'); + benv.require('../stop-angular-overrides.js'); + + var module = angular.module('A', []); + var filter = function () {}; + + module.filter('aFilter', function () { return filter; }); + + QUnit.throws(function() { + module.filter('aFilter'); + }, 'Error'); +});