Repository: angular/angular.js
File: test/auto/injectorSpec.js (JavaScript)

Code before:
    it('should be able to register a filter from a new module', function() {
      var injector = createInjector(['ng']);
      angular.module('a', []);
      angular.module('a').filter('aFilter', function() {
        return function(input) { return input + ' filtered'; };
      });
      injector.loadNewModules(['a']);
      injector.invoke(function($filter) {
        var filter = $filter('aFilter');
        expect(filter('test')).toEqual('test filtered');
      });
    });


    it('should be able to register a directive from a new module', function() {
      var injector = createInjector(['ng']);
      angular.module('a', []);
      angular.module('a').directive('aDirective', function() {
        return {  template: 'test directive' };
      });
      injector.loadNewModules(['a']);
      injector.invoke(function($compile, $rootScope) {
        var scope = $rootScope.$new();
        var html = '<div a-directive></div>';
        var elem = angular.element(html);
        $compile(elem)(scope);  // compile and link
        scope.$digest();
        expect(elem.text()).toEqual('test directive');
        elem.remove();
      });
    });
  });

  it('should have a false strictDi property', inject(function($injector) {
    expect($injector.strictDi).toBe(false);
  }));


  describe('invoke', function() {
    var args;

    beforeEach(function() {
      args = null;
      providers('a', function() {return 1;});
      providers('b', function() {return 2;});
    });


    function Fn(a, b, c, d) {
      args = [this, a, b, c, d];
      return a + b + c + d;

Review comment (suggestion):
Save up to three(3) lines with:

```js
var elem = $compile('<div a-directive></div>')($rootScope);
$rootScope.$digest();
```

🌿 

Code after:
      angular.module('a', []).filter('aFilter', function() {
        return function(input) { return input + ' filtered'; };
      });
      injector.loadNewModules(['a']);
      injector.invoke(function(aFilterFilter) {
        expect(aFilterFilter('test')).toEqual('test filtered');
      });
    });


    it('should be able to register a directive from a new module', function() {
      var injector = createInjector(['ng']);
      angular.module('a', []).directive('aDirective', function() {
        return {template: 'test directive'};
      });
      injector.loadNewModules(['a']);
      injector.invoke(function($compile, $rootScope) {
        var elem = $compile('<div a-directive></div>')($rootScope);  // compile and link
        $rootScope.$digest();
        expect(elem.text()).toEqual('test directive');
        elem.remove();
      });
    });
  });

  it('should have a false strictDi property', inject(function($injector) {
    expect($injector.strictDi).toBe(false);
  }));


  describe('invoke', function() {
    var args;

    beforeEach(function() {
      args = null;
      providers('a', function() {return 1;});
      providers('b', function() {return 2;});
    });


    function Fn(a, b, c, d) {
      args = [this, a, b, c, d];
      return a + b + c + d;
    }


    it('should call function', function() {
      Fn.$inject = ['a', 'b', 'c', 'd'];
      injector.invoke(Fn, {name:'this'},  {c:3, d:4});
      expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]);
    });