Created
July 23, 2014 09:01
-
-
Save karlwestin/e9972472149ab0e8e03b to your computer and use it in GitHub Desktop.
angular testing
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
// from https://code.angularjs.org/1.2.19/docs/guide/unit-testing | |
// under 'simple html element directive' | |
// Whats the beef? | |
// One of angular's flagship features, dependency injection | |
// forces us to write clumsy **beforeEach clauses** leaks the instances one level up in scope | |
// And the argumentation for the use of this weird DI is TESTING???? | |
// writing large test suites leaking variables one step up | |
// usually leads to making the impossible to run next to each other | |
//wtf | |
var $compile; | |
var $rootScope; | |
// Load the myApp module, which contains the directive | |
beforeEach(module('myApp')); | |
// Store references to $rootScope and $compile | |
// so they are available to all tests in this describe block | |
beforeEach(inject(function(_$compile_, _$rootScope_){ | |
// The injector unwraps the underscores (_) from around the parameter names when matching | |
$compile = _$compile_; | |
$rootScope = _$rootScope_; | |
})); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nope, see here: https://gist.github.com/karlwestin/7506ec6c234ef32679c4