-
Notifications
You must be signed in to change notification settings - Fork 129
Closed
Description
Typically an AngularJS test file looks similar to this.
describe('kittenService', function() {
var $httpBackend;
var kittenService;
beforeEach(module('myApp'));
beforeEach(inject(function(_$httpBackend_, kittenService) {
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/kittens/).respond([]);
kittenService = kittenService;
kittenService.initialize();
}));
it(...);
});I think it is more readable to keep the dependency injection separated from the other setup logic.
describe('kittenService', function() {
var $httpBackend;
var kittenService;
beforeEach(module('myApp'));
// Inject dependencies
beforeEach(inject(function(_$httpBackend_, _kittenService_) {
$httpBackend = _$httpBackend_;
kittenService = _kittenService_;
}));
// Do initial setup which might be messy in some cases.
beforeEach(function() {
$httpBackend.whenGET(/kittens/).respond([]);
kittenService.initialize();
});
it(...);
});This rule comes down to: If inject is called, the passed function may only contain (sorted) statements of the form arg = _arg_.