Skip to content

AndersDJohnson/angular-inject-into

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-inject-into

Angular injection into an object. DRY and minification-safe. E.g. to simplify angular.mock.inject beforeEach assignment boilerplate in Jasmine tests.

You can now do this:

describe('test', function () {
  var inj = {};

  beforeEach(inject(injectInto(['$rootScope', '$http', '$location'], inj)));

  it('inject', function () {
    expect(inj.$rootScope).toBeDefined();
    expect(inj.$http).toBeDefined();
    expect(inj.$location).toBeDefined();
  });
});

Instead of this:

describe('test', function () {
  var $rootScope;
  var $http;
  var $location;

  beforeEach(inject(function (_$rootScope_, _$http_, _$location_) {
    $rootScope = _$rootScope_;
    $http = _$http_;
    $location = _$location_;
  }));

  it('inject', function () {
    expect($rootScope).toBeDefined();
    expect($http).toBeDefined();
    expect($location).toBeDefined();
  });
});

About

Angular injection into object. DRY & minification-safe. Simplify inject beforeEach boilerplate in tests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published