Skip to content

Instantly share code, notes, and snippets.

@karlwestin
Created July 23, 2014 09:01
Show Gist options
  • Save karlwestin/e9972472149ab0e8e03b to your computer and use it in GitHub Desktop.
Save karlwestin/e9972472149ab0e8e03b to your computer and use it in GitHub Desktop.
angular testing
// 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_;
}));
@karlwestin
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment