-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hintController): set up initial repository
- Loading branch information
Erin Altenhof-Long
committed
Jul 2, 2014
1 parent
7fc54cc
commit 6f141d9
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/bower_components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Decorates $controller with a patching function to | ||
* throw an error if DOM APIs are manipulated from | ||
* within an Angular controller | ||
*/ | ||
angular.module('ngHintController', []). | ||
config(function ($provide) { | ||
$provide.decorator('$controller', function($delegate, $injector) { | ||
return function(ctrl, locals) { | ||
if(angular.isString(ctrl)) { | ||
match = expression.match(CNTRL_REG), | ||
constructor = match[1], | ||
identifier = match[3]; | ||
ctrl = controllers.hasOwnProperty(constructor) | ||
? controllers[constructor] | ||
: console.log('Not on window') || console.log('It is against Angular best practices to instantiate a controller on the window.'); | ||
} | ||
var ctrlInstance = $delegate.apply(this, [ctrl, locals]); | ||
return ctrlInstance; | ||
} | ||
}); | ||
}); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe('controllerDecorator', function() { | ||
var $controller; | ||
|
||
beforeEach(module('ngHintController')); | ||
|
||
beforeEach(inject(function(_$controller_) { | ||
$controller = _$controller_; | ||
})); | ||
|
||
it('should detect if a controller is instantiated on the window', function() { | ||
spyOn(console, 'log'); | ||
var controllerMock = function() { | ||
var element = document.createElement('a'); | ||
element.innerHTML = 'testValue'; | ||
}; | ||
var sampleControl = $controller(controllerMock); | ||
expect(console.log).toHaveBeenCalledWith('It is against Angular best practices to instantiate a controller on the window.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
frameworks: ['jasmine'], | ||
files: [ | ||
'bower_components/angular/angular.js', | ||
'bower_components/angular-mocks/angular-mocks.js', | ||
'controllerDecorator.js', | ||
'controllerDecorator_test.js' | ||
], | ||
exclude: [ | ||
], | ||
preprocessors: { | ||
}, | ||
browsers: ['Chrome'] | ||
}); | ||
}; |